PHP- 无法在 xampp 中更改 max_execution_time
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11284731/
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
PHP- cannot change max_execution_time in xampp
提问by mk_89
I've tried everything to change the max_execution_timeof a php crawler script so that it can run an infinite amount of time.
我已经尝试了所有方法来更改max_execution_timephp 爬虫脚本,以便它可以无限运行。
I have changed the php.ini file setting max_execution_timeto 0or 100000000but with no change
我已将 php.ini 文件设置更改max_execution_time为0或100000000但没有更改
I've also tried setting it from the php script itself by using ini_set('max_execution_time', 0);
我还尝试使用 php 脚本本身设置它 ini_set('max_execution_time', 0);
All php scripts throw the same error Fatal error: Maximum execution time of 3000 seconds exceeded, what could I be missing and how can I make sure there is no max execution time limit?
所有 php 脚本都抛出相同的错误Fatal error: Maximum execution time of 3000 seconds exceeded,我可能会遗漏什么,我如何确保没有最大执行时间限制?
php script
php脚本
<?php
ini_set('MAX_EXECUTION_TIME', -1);
error_reporting(E_ALL); // turn on all errors, warnings and notices for easier debugging
//ini_set('max_execution_time', 123456);
ini_set('max_input_time', -1);
ini_set('memory_limit', '512M');
set_time_limit(0);
date_default_timezone_set('Europe/London');
/*code which scrapes websites*/
?>
phpinfo()
phpinfo()
max_execution_time 0 0
max_input_time -1 -1
采纳答案by Ja?ck
You shouldn't let your crawler run under apache, it's better to run it stand-alone via cli as part of a Gearmansetup.
你不应该让你的爬虫在 apache 下运行,最好通过 cli 作为Gearman设置的一部分独立运行它。
That way it won't hog your web server and it can run as long as you want. You can find many bindings for Gearman that you can use, including PHP of course.
这样它就不会占用您的网络服务器,并且可以根据您的需要运行。您可以找到许多可以使用的 Gearman 绑定,当然包括 PHP。
回答by LoneWOLFs
Try turning off safe modein php and then try the below code
尝试在 php 中关闭安全模式,然后尝试以下代码
if( !ini_get('safe_mode') ){
set_time_limit(0); //this won't work if safe_mode is enabled.
}
This should allow you to run the script for infinite time.
这应该允许您无限时间运行脚本。
In Apache you can change maximum execution time by .htaccess with this line
在 Apache 中,您可以使用此行通过 .htaccess 更改最大执行时间
php_value max_execution_time 200
回答by Learner
use
用
set_time_limit(0);
at the top of the script
在脚本的顶部
回答by Bas Wildeboer
I found the following in the xampp documentation. Maybe you are trying to edit the wrong php.ini file?
我在xampp 文档中找到了以下内容。也许您正在尝试编辑错误的 php.ini 文件?
Why have changes in my php.ini no effect?
Since XAMPP 1.7.1 the "php.ini" is only in the directory "\xampp\php". Till XAMPP 1.7.0 is was in the directory "\xampp\apache\bin".
If a change in the "php.ini" have no effect, it's possible PHP is still using an other one. You can verify this with phpinfo(). Go to the URI localhost/xampp/phpinfo.php and search for "Loaded Configuration File". This value shows you the "php.ini" PHP is really using.
Info: After changing the "php.ini" you have to restart Apache, thus Apache/PHP can read the new settings.
为什么在我的 php.ini 中有改动没有效果?
从 XAMPP 1.7.1 开始,“php.ini”仅在目录“\xampp\php”中。直到 XAMPP 1.7.0 位于目录“\xampp\apache\bin”中。
如果“php.ini”中的更改无效,则 PHP 可能仍在使用另一个。您可以使用 phpinfo() 验证这一点。转到 URI localhost/xampp/phpinfo.php 并搜索“加载的配置文件”。这个值显示了 PHP 真正使用的“php.ini”。
信息:更改“php.ini”后,您必须重新启动Apache,这样Apache/PHP 才能读取新设置。
回答by Dev
what you are doing is just setting the max_execution_timeto whatever inside your page.
you can't change this using ini_set. you can change the memory_limitonly.
您正在做的只是将 设置为max_execution_time页面内的任何内容。您无法使用 ini_set 更改此设置。你可以改变memory_limit唯一的。
see more details here...from the php official site.
在此处查看更多详细信息...来自 php 官方网站。
if you want them to be changed, change in php.ini.
如果您希望更改它们,请在 php.ini 中更改。
回答by Peon
You have to change both of these in you php.ini ( and check if that's the right php.ini by finding the location in phpinfo();output! )
您必须在 php.ini 中更改这两个(并通过在phpinfo();输出中找到位置来检查这是否是正确的 php.ini !)
max_execution_time = 0
max_input_time = 0
And after that check if some php file is not overwriting those variables locally.
然后检查某些 php 文件是否没有在本地覆盖这些变量。
回答by vasanth252
open php.ini notepad file and search or find upload_max_filesize = 1000Mand you should change on Post_max_filesize = 1000Mthen restart your xampp and refresh the local phpmyadmin..
打开php.ini记事本文件并搜索或查找upload_max_filesize = 1000M,您应该更改Post_max_filesize = 1000M然后重新启动xampp并刷新本地phpmyadmin ..
回答by Dale
You could also try setting ignore_user_abort(TRUE);in your script as it might be the browser timing out rather than the script.
您也可以尝试ignore_user_abort(TRUE);在脚本中进行设置,因为它可能是浏览器超时而不是脚本超时。
From the php.net manual
来自 php.net 手册
<?php
// Ignore user aborts and allow the script
// to run forever
ignore_user_abort(true);
set_time_limit(0);
See here for more info
在这里查看更多信息
回答by Cups
If you are on windows, and this is a CLI run script maybe read this.
如果您使用的是 Windows,并且这是一个 CLI 运行脚本,请阅读此.
回答by user1402647
check phpinfo()from a temp script and search for max_execution_time. make sure that it has same value what you are setting. default should be 30 seconds. try to change it to a couple of different values and restart apache then check the value in phpinfo()to confirm.
phpinfo()从临时脚本中检查并搜索max_execution_time. 确保它与您设置的值相同。默认应为 30 秒。尝试将其更改为几个不同的值并重新启动 apache,然后检查该值以phpinfo()进行确认。
if when you change the value it is reflected properly in the phpinfo()it means that there is some code in your script which is changing this value. search for two things in your code:
如果当您更改该值时,它会正确反映在 中,phpinfo()则意味着您的脚本中有一些代码正在更改此值。在代码中搜索两件事:
- search your code for
ini_set()and check if it is changemax_execution_time - search for
set_time_limit()
- 搜索您的代码
ini_set()并检查它是否更改max_execution_time - 搜索
set_time_limit()
these functions can change maximum time limit of execution from script. otherwise you should check .htaccessfrom where this value may be set. but this will effect phpinfo()also.
这些函数可以更改脚本的最大执行时间限制。否则你应该检查.htaccess从哪里可以设置这个值。但这也会影响phpinfo()。

