[英]Max Execution Time error despite setting php.ini correctly
I have been struggling with this for past one hour. 过去一个小时,我一直在为此苦苦挣扎。 I am using WAMP Local server on windows maching so everything is under my control.
我在Windows机上使用WAMP Local服务器,所以一切都在我的控制之下。 I am getting maximum execution time 60 seconds error when trying to import Wordpress xml file.
尝试导入Wordpress xml文件时出现最大执行时间60秒错误。
I have set these values in php.ini:
我已经在
php.ini:
设置了这些值php.ini:
max_execution_time = 1200
memory_limit = 512M
max_input_time = -1
I have also edited my wp-config file : set_time_limit(0);
I restarted server after making changes. 进行更改后,我重新启动了服务器。 Still I get error
还是我出错
) Fatal error: Maximum execution time of 60 seconds exceeded in C:\wamp\www\xxa\wp-includes\wp-db.php on line 1285
Thanks Ahmar 谢谢阿马尔
This must have something to do with the hard coded max_execution_time set to 60. 这必须与硬编码的max_execution_time设置为60有关。
I had the same issue with the WordPress Importer. 我在WordPress导入程序中遇到了同样的问题。 Turned out it was because of the hard coded
@set_time_limit( 60 )
in the wp-includes/functions.php
file: 原来是由于
wp-includes/functions.php
文件中的硬编码@set_time_limit( 60 )
:
function wp_get_http( $url, $file_path = false, $red = 1 ) { @set_time_limit( 60 );
I commented out the set_time_limit( 60 )
call and it worked fine after that: 我注释掉了
set_time_limit( 60 )
调用,此后它运行良好:
//@set_time_limit( 60 );
This problem can arise when the inital check performed by the plugin takes more than 30 seconds. 当插件执行的初始检查时间超过30秒时,可能会出现此问题。
Please try either: 请尝试:
Important – If you are making changes in wp-config.php, then add this line above the “/* That's all, stop editing! 重要提示–如果要在wp-config.php中进行更改,请在“ / *”上方添加此行,那就停止编辑! Happy blogging.
快乐的博客。 */” comment.
* /”评论。
Adapting the /.htaccess file of your WordPress installation php_value max_execution_time 60 修改WordPress安装的/.htaccess文件php_value max_execution_time 60
Adapting the php.ini file max_execution_time = 60; 修改php.ini文件max_execution_time = 60;
Preferably the changes are made in the wp-config.php file. 最好在wp-config.php文件中进行更改。
Please let me know if that solves the issue. 请让我知道是否可以解决问题。
Thanks 谢谢
I had to test register_shutdown_function() myself -- I didn't think it'd run. 我必须自己测试register_shutdown_function()-我认为它不会运行。 After all, how can a user function run once there's no more memory, or execution time has elapsed?
毕竟,一旦没有更多的内存或执行时间过去了,用户功能如何运行? I was surprised to learn that shutdown functions do run, even in an OOM situation, or when execution time has been exceded.
我很惊讶地发现关机功能确实可以运行,即使在OOM情况下,或者在执行时间已超过时,我也感到惊讶。 Proof of concept: To test memory limit:
概念验证:要测试内存限制:
<?php
function asdf() { echo "omg\n"; }
register_shutdown_function('asdf');
ini_set('memory_limit', '1000');
$x = '';
while(true) {
$x .= 'lkajsdlfkjasldkfjlaskdfjasldkfj';
}
Output: 输出:
PHP Fatal error: Allowed memory size of 262144 bytes exhausted (tried to allocate 169540 bytes) in /home/scratch.php on line 9
PHP Stack trace:
PHP 1. {main}() /home/scratch.php:0
Fatal error: Allowed memory size of 262144 bytes exhausted (tried to allocate 169540 bytes) in /home/scratch.php on line 9
Call Stack:
0.0002 81360 1. {main}() /home/scratch.php:0
omg
To test execution time: 要测试执行时间:
cat scratch.php
<?php
function asdf() { echo "omg\n"; }
register_shutdown_function('asdf');
set_time_limit(1);
while(true) {}
Output: 输出:
PHP Fatal error: Maximum execution time of 1 second exceeded in /home/scratch.php on line 7
PHP Stack trace:
PHP 1. {main}() /home/scratch.php:0
Fatal error: Maximum execution time of 1 second exceeded in /home/scratch.php on line 7
Call Stack:
0.0002 80200 1. {main}() /home/scratch.php:0
omg
Note that, to get your message to display before PHP's error output, you'd have to disable PHP's error output entirely. 请注意,要使您的消息在PHP的错误输出之前显示,您必须完全禁用PHP的错误输出。 Which is best practice for a production site anyway.
无论如何,这是生产现场的最佳实践。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.