1
<?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.

我不想增加 max_execution_time 但我想减少脚本运行时间。

4

1 回答 1

0

您正在收集整个页面。为什么不只指定$maxlen参数并或多或少地获取标题标签所在页面的标题?这会给你一点加速。

string file_get_contents ( string $filename [, bool $use_include_path = false [, resource $context [, int $offset = -1 [, int $maxlen ]]]] )

于 2012-05-25T11:16:07.750 回答