如何设置 PHP 脚本的最长执行时间?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5638484/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 22:02:53  来源:igfitidea点击:

How can I set the maximum execution time for a PHP script?

phpapacheexecution-time

提问by Nick Q.

I would like to change the maximum execution time for a PHP script. In the script I have tried

我想更改 PHP 脚本的最长执行时间。在我尝试过的脚本中

ini_set("max_execution_time", "1000");

and

set_time_limit(1000);

together and separately.

一起和分开。

I also added this line to .htaccess:

我还将这一行添加到 .htaccess 中:

php_value max_execution_time 1000

php.ini has safemode off and the Apache server has the flag AllowOverride All. What must I do to get the server to allow a longer execution time?

php.ini 关闭了安全模式并且 Apache 服务器有标志AllowOverride All。我必须做什么才能让服务器允许更长的执行时间?

回答by Bryan Agee

Setting the variable in the ini file works for me:

在ini文件中设置变量对我有用:

max_execution_time = 1000;

set_time_limit() should work as well, as long as it's not in safe mode.

set_time_limit() 应该也能工作,只要它不在安全模式下。

回答by Lukas

If you're looking for an Apache2-directive to use in .htaccess or the configuration of one VirtualHost, you probably need php_admin_value:

如果您正在寻找在 .htaccess 中使用的 Apache2 指令或一个 VirtualHost 的配置,您可能需要 php_admin_value:

php_admin_value max_execution_time 1000

AFAIK this only works with mod_php

AFAIK 这仅适用于 mod_php