我收到了可怕的消息:
Fatal error: Maximum execution time of 90 seconds exceeded in /home/pricing.php on line 239
Run Code Online (Sandbox Code Playgroud)
代码是:
$url = "http://*******.com/feed?f=PR&categories=$cat_id&limit=100&startproducts=$ii&price_min=0.01&sortproducts=score&show=properties";
$c = curl_init($url);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_HEADER, 0);
curl_setopt($c, CURLOPT_USERPWD, "****:****");
$xml = simplexml_load_string(curl_exec($c)); // line 239
Run Code Online (Sandbox Code Playgroud)
simplexml_load_string是239行,这肯定意味着已经获得了feed(因为想要一个更好的词!)并且正在加载字符串,但肯定不会超过90秒?
我的问题是:
1 - 可能/会导致什么?
2 - 增加php_value max_execution_time90秒以上是安全的吗?安全最大值是多少?
3 - 是否有更好/更快/更稳定的方式来降低饲料而不是使用卷曲?
谢谢大家的帮助!
A1:是的,你从第二个问题得到答案.它是由php引起的max_execution_time.
A2:这不安全,除非你在本地托管它并且你知道你的脚本正在做什么.我认为通常的做法是30秒或最长300秒(5分钟).
A3如果你正在处理curl,我更喜欢你设置set_time_limit(0)你的PHP脚本的顶部(代码级别相当于max_execution_timein php.ini),并使用curl的超时来处理超时.
curl_setopt($curl, CURLOPT_TIMEOUT_MS, 2000); //in miliseconds
Run Code Online (Sandbox Code Playgroud)