增加 php 的最大执行时间
我添加了 set_time_limit(0);
函数来增加执行时间,但最多只执行 2-3 分钟。
error_reporting(E_ALL);
error_reporting(1);
set_time_limit(0);
我想从一个需要很长时间的网站搜索链接。
I have added set_time_limit(0);
function to increase execution time but its executing only 2-3 minutes maximum.
error_reporting(E_ALL);
error_reporting(1);
set_time_limit(0);
I want to search links from a site which is taking a long time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
PHP 文件(例如 my_lengthy_script.php)
.htaccess 文件
更多配置选项
如果是 WordPress,请在 config.php 中进行设置文件,
如果是drupal,则为sites/default/settings.php
如果您使用其他框架,
您可以将内存增加为千兆字节 。
259200 意味着:-
更多详情见我的博客
PHP file (for example, my_lengthy_script.php)
.htaccess file
More configuration options
If wordpress, set this in the config.php file,
If drupal, sites/default/settings.php
If you are using other frameworks,
You can increase memory as gigabyte.
259200 means:-
More details on my blog
将这些代码行添加到您的 htaccess 文件中。我希望它能解决您的问题。
Add these lines of code in your htaccess file. I hope it will solve your problem.
好吧,由于您位于共享服务器上,因此您无能为力。他们通常会设置最大执行时间,以便您无法覆盖它。我建议你联系他们。
Well, since your on a shared server, you can't do anything about it. They usually set the max execution time so that you can't override it. I suggest you contact them.
嗯,有两种方法可以更改 max_execution_time。
1.可以直接在php.ini文件中设置。
2. 其次,您可以在代码中添加以下行。
well, there are two way to change max_execution_time.
1. You can directly set it in php.ini file.
2. Secondly, you can add following line in your code.
使用 mod_php7.c 而不是 mod_php5.c
对于 PHP 7示例,
Use mod_php7.c instead of mod_php5.c for PHP 7
Example
您的网络服务器中可能设置了限制。一些浏览器/代理也会实现超时。通过 HTTP 请求调用长时间运行的进程是非常愚蠢的。解决问题的正确方法(假设您无法加快处理速度)是使用 HTTP 请求触发 Web 服务器会话组之外的处理,然后通过 HTTP 轮询状态,直到获得结果集。
There's probably a limit set in your webserver. Some browsers/proxies will also implement a timeout. Invoking long running processes via an HTTP request is just plain silly. The right way to solve the problem (assuming you can't make the processing any faster) is to use the HTTP request to trigger processing outside of the webserver session group then poll the status via HTTP until you've got a result set.
这是一个老问题,但如果今天有人发现它,那么 php 很可能会通过 php-fpm 和 mod_fastcgi 运行。在这种情况下,这里没有任何内容可以帮助延长执行时间,因为 Apache 将终止与 30 秒内不输出任何内容的进程的连接。扩展它的唯一方法是更改 apache (模块/站点/虚拟主机) 配置中的 -idle-timeout 。
更多详细信息 - 增加 PHP-FPM 空闲超时设置
This is old question, but if somebody finds it today chances are php will be run via php-fpm and mod_fastcgi. In that case nothing here will help with extending execution time because Apache will terminate connection to a process which does not output anything for 30 seconds. Only way to extend it is to change -idle-timeout in apache (module/site/vhost) config.
More details - Increase PHP-FPM idle timeout setting
尝试设置更长的
max_execution_time
:Try to set a longer
max_execution_time
: