设置 ini max_execution_time 不起作用 [英] Set ini max_execution_time doesn't work

查看:45
本文介绍了设置 ini max_execution_time 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我使用 nginx 和 php-fpm 之前,我使用了 Apache,所以当我只想我的一个 cron 作业在没有时间执行限制的情况下运行时,我在我的 PHP 代码中使用了这些行:

Before I use nginx and php-fpm, I used Apache, so when I wanted only one of my cron jobs to run without time execution limitation, I used these lines in my PHP code:

set_time_limit(0);
ini_set('max_execution_time', 0); 

但是在我从 Apache 迁移到 nginx 后,此代码不起作用.我知道如何更改 nginx.conf 以增加最大执行时间.

but after I migrated from Apache to nginx, this code doesn't work. I know ways to change nginx.conf to increase maximum execution time.

但我想用 php 代码来处理这个问题.有办法吗?我只想指定一个可以不受时间限制运行PHP代码的文件.

But I want to handle this with php code. Is there a way? I want to specify only one file that can run PHP code without time limitation.

推荐答案

试试这个:

使用 Nginx

您可以按照下面给出的步骤来增加超时值.PHP 默认为 30 秒.:

如果您想将 php 脚本的最大执行时间限制从 30 秒(默认)更改为 300 秒.

If you want to change max execution time limit for php scripts from 30 seconds (default) to 300 seconds.

vim /etc/php5/fpm/php.ini

设置...

max_execution_time = 300

在 Apache 中,将 PHP 作为上述模块运行的应用程序就足够了.但在我们的例子中,我们需要在另外 2 个地方进行此更改.

In Apache, applications running PHP as a module above would have suffice. But in our case we need to make this change at 2 more places.

PHP-FPM 的变化

这仅在您之前已经取消注释 request_terminate_timeout 参数时才需要.默认为注释,取php.ini中的max_execution_time值

This is only needed if you have already un-commented request_terminate_timeout parameter before. It is commented by default, and takes value of max_execution_time found in php.ini

编辑...

vim /etc/php5/fpm/pool.d/www.conf

设置...

request_terminate_timeout = 300

Nginx 配置的变化

增加example.com的时间限制

To increase the time limit for example.com by

vim /etc/nginx/sites-available/example.com

location ~ .php$ {
    include /etc/nginx/fastcgi_params;
        fastcgi_pass  unix:/var/run/php5-fpm.sock;
    fastcgi_read_timeout 300; 
}

如果你想增加服务器上所有站点的时间限制,你可以编辑主 nginx.conf 文件:

If you want to increase time-limit for all-sites on your server, you can edit main nginx.conf file:

vim /etc/nginx/nginx.conf

在 http{..} 部分添加以下内容

Add following in http{..} section

http {
    #...
        fastcgi_read_timeout 300; 
    #...
}

重新加载 PHP-FPM &nginx

不要忘记这样做,以便您所做的更改生效:

Don’t forget to do this so that changes you have made will come into effect:

service php5-fpm reload
service nginx reload

或者试试这个

fastcgi_send_timeout 50;
fastcgi_read_timeout 50;

fastcgi 有它自己的一组超时和检查,以防止它在锁定的进程中停滞不前.例如,如果您将 php 的执行时间限制设置为 0(无限制),然后不小心创建了一个无限循环,它们就会启动.或者,如果您正在运行除 PHP 之外的其他应用程序,这些应用程序没有任何自己的超时保护并且失败了.

fastcgi has it's own set of timeouts and checks to prevent it from stalling out on a locked up process. They would kick in if you for instance set php's execuction time limit to 0 (unlimited) then accidentally created an infinite loop. Or if you were running some other application besides PHP which didn't have any of it's own timeout protections and it failed.

这篇关于设置 ini max_execution_time 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆