gpt4 book ai didi

php - curl_exec 最长执行时间 - 是什么原因造成的?

转载 作者:可可西里 更新时间:2023-11-01 12:52:42 27 4
gpt4 key购买 nike

我收到了可怕的消息:

Fatal error: Maximum execution time of 90 seconds exceeded in /home/pricing.php on line 239

代码是:

$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

simplexml_load_string 是第 239 行,这肯定意味着已经获取了提要(需要一个更好的词!)并且正在加载字符串,但是肯定不会超过 90 秒吗?

我的问题是:

1 - 什么可能/会导致这种情况?

2 - 将 php_value max_execution_time 增加到 90 秒以上是否安全,什么是安全的最大值?

3 - 是否有比使用 curl 更好/更快/更稳定的降低提要的方法?

感谢大家的帮助!

最佳答案

A1:是的,您从第二个问题中得到了答案。这是由 php 的 max_execution_time 引起的。

A2:它不安全,除非你在本地托管它并且你知道你的脚本在做什么。我认为通常的做法是 30 秒或最多 300 秒(5 分钟)。

A3如果您正在处理 curl,我希望您在 php 脚本的最顶部设置 set_time_limit(0)(代码级别相当于 php.ini 中的 max_execution_time ),使用curl的timeout来处理超时。

curl_setopt($curl, CURLOPT_TIMEOUT_MS, 2000); //in miliseconds

关于php - curl_exec 最长执行时间 - 是什么原因造成的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8374008/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com