English 中文(简体)
脚本需要超过 30 秒才能在 php 中取得标题 URL 。
原标题:script taking more than 30 second to get title url in php
<?php
function getTitle($Url){
    $str = file_get_contents($Url);
    if(strlen($str)>0){
        preg_match("/<title>(.*)</title>/",$str,$title);
        return $title[1];
    }
}
echo getTitle("http://www.stackoverflow.com/");
?>

当我运行此脚本时, 它返回错误

max_execution_time exceeds 30 second.

我不想增加最大执行时间, 但我想减少脚本运行时间 。

最佳回答

您重新收集整个页面。 为什么不指定 < code> $maxlen palm 来获取标题标签所在页面的页眉? 这将给您一些速度 。

string file_get_contents (字符串 $filename [, bull $use_ including_ path = 假 [, 资源 $text [, int $offsets = - 1 [, int $t $maxlen ] ] ] ]

问题回答

暂无回答




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签