我有一张20000左右的表格,其中包含未经处理的Youtube帖子。 这个表是使用cronjob自动填充的,它可以正常工作。 现在我有了一个代码,它只能在所有帖子都被处理后退出。
为此,我必须使用curl从youtube获取其他信息。 我的代码运行正常,但在随机的时间/帖子之后,我收到致命的错误:
PHP致命错误:超过30秒的最长执行时间 /home/local/domains/domain.com/private/include/classes/Youtube.php on 第183行
这是代码:
public function api_get($url, $params)
{
error_log(__FILE__."::".__LINE__." - ".date("U"), 0);
//set the youtube key
$params["key"] = $this->youtube_key;
//boilerplates for CURL
$tuCurl = curl_init();
error_log(__FILE__."::".__LINE__." - ".date("U"), 0);
curl_setopt_array($tuCurl, array(
CURLOPT_URL => $url . (strpos($url, "?") === false ? "?" : "") . http_build_query($params),
CURLOPT_PORT => strpos($url, "https") === false ? 80 : 443,
CURLOPT_CONNECTTIMEOUT => 30,
CURLOPT_FRESH_CONNECT => true,
CURLOPT_FORBID_REUSE => true,
CURLOPT_TIMEOUT => 60,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_MAXREDIRS => 5,
CURLOPT_NOPROGRESS => false // only for debugging purposes
));
error_log(__FILE__."::".__LINE__." - ".date("U"), 0);
$tuData = curl_exec($tuCurl);
error_log(__FILE__."::".__LINE__." - ".date("U"), 0);
if (curl_errno($tuCurl)) {
$curlError = curl_error($tuCurl);
error_log(__FILE__."::".__LINE__." - ".date("U"), 0);
curl_close($tuCurl);
error_log(__FILE__."::".__LINE__." - ".date("U"), 0);
throw new Elision("[#505011] "._("Curl Error:")." ". $curlError);
}
error_log(__FILE__."::".__LINE__." - ".date("U"), 0);
curl_close($tuCurl);
error_log(__FILE__."::".__LINE__." - ".date("U"), 0);
return $tuData;
}
我使用error_log
找出问题所在,当我使用SSH运行此代码时,我得到了这个(我只显示最后几行):
/home/local/domains/localthisday.nl/private/socket/youtube_parsing.php::35 - 1426757941 /home/local/domains/localthisday.nl/private/socket/youtube_parsing.php::37 - 1426757941 /home/local/domains/localthisday.nl/private/socket/youtube_parsing.php::45 - 1426757941 /home/local/domains/localthisday.nl/private/socket/youtube_parsing.php::47 - 1426757941 /home/local/domains/localthisday.nl/private/socket/youtube_parsing.php::49 - 1426757941 /home/local/domains/localthisday.nl/private/socket/youtube_parsing.php::51 - 1426757941 /home/local/domains/localthisday.nl/private/socket/youtube_parsing.php::56 - 1426757941 /home/local/domains/localthisday.nl/private/socket/youtube_parsing.php::18 - 1426757941 /home/local/domains/localthisday.nl/private/socket/youtube_parsing.php::20 - 1426757941 /home/local/domains/localthisday.nl/private/socket/youtube_parsing.php::22 - 1426757941 /home/local/domains/localthisday.nl/private/socket/youtube_parsing.php::24 - 1426757941 /home/local/domains/localthisday.nl/private/socket/youtube_parsing.php::26 - 1426757941 /home/local/domains/localthisday.nl/private/socket/youtube_parsing.php::28 - 1426757941 /home/local/domains/localthisday.nl/private/socket/youtube_parsing.php::31 - 1426757941 /home/local/domains/localthisday.nl/private/socket/youtube_parsing.php::33 - 1426757941 /home/local/domains/localthisday.nl/private/include/classes/Youtube.php::163 - 1426757941 /home/local/domains/localthisday.nl/private/include/classes/Youtube.php::169 - 1426757941 /home/local/domains/localthisday.nl/private/include/classes/Youtube.php::182 - 1426757941 %总收到百分比%Xferd平均速度时间时间当前时间 Dload上载总左转速度 102 1131 102 1131 0 0 4238 0 - : - : - - : - : - - : - : - 15080 /home/local/domains/localthisday.nl/private/include/classes/Youtube.php::184 - 1426757941 /home/local/domains/localthisday.nl/private/include/classes/Youtube.php::192 - 1426757941 /home/local/domains/localthisday.nl/private/include/classes/Youtube.php::194 - 1426757941 /home/local/domains/localthisday.nl/private/socket/youtube_parsing.php::35 - 1426757941 /home/local/domains/localthisday.nl/private/socket/youtube_parsing.php::37 - 1426757941 /home/local/domains/localthisday.nl/private/socket/youtube_parsing.php::45 - 1426757941 /home/local/domains/localthisday.nl/private/socket/youtube_parsing.php::47 - 1426757941 /home/local/domains/localthisday.nl/private/socket/youtube_parsing.php::49 - 1426757941 /home/local/domains/localthisday.nl/private/socket/youtube_parsing.php::51 - 1426757941 /home/local/domains/localthisday.nl/private/socket/youtube_parsing.php::56 - 1426757941 /home/local/domains/localthisday.nl/private/socket/youtube_parsing.php::18 - 1426757941 /home/local/domains/localthisday.nl/private/socket/youtube_parsing.php::20 - 1426757941 /home/local/domains/localthisday.nl/private/socket/youtube_parsing.php::22 - 1426757941 /home/local/domains/localthisday.nl/private/socket/youtube_parsing.php::24 - 1426757941 /home/local/domains/localthisday.nl/private/socket/youtube_parsing.php::26 - 1426757941 /home/local/domains/localthisday.nl/private/socket/youtube_parsing.php::28 - 1426757941 /home/local/domains/localthisday.nl/private/socket/youtube_parsing.php::31 - 1426757941 /home/local/domains/localthisday.nl/private/socket/youtube_parsing.php::33 - 1426757941 /home/local/domains/localthisday.nl/private/include/classes/Youtube.php::163 - 1426757941 /home/local/domains/localthisday.nl/private/include/classes/Youtube.php::169 - 1426757941 /home/local/domains/localthisday.nl/private/include/classes/Youtube.php::182 - 1426757941 PHP致命错误:/home/local/domains/localthisday.nl/private/include/classes/Youtube.php中超过30秒的最长执行时间 在第183行
正如您所看到的,相同的代码运行正常,但下一次,它不会运行并产生致命错误。 当我重新运行脚本时,它也会随机运行一段时间,然后再次崩溃,因此它不能作为输入URL。
任何想法如何解决这个问题我都不会得到致命的错误?
编辑:
我忘了添加:
函数api_get在类Youtube.php
中。
我从名为youtube_parsing.php
的文件中运行此代码。
在youtube_parsing.php
我这样做是为了避免执行限制:
set_time_limit(0);
ini_set("max_execution_time", 0);