尽管正确设置了php.ini,但最大执行时间错误


Max Execution Time error despite setting php.ini correctly

在过去的一个小时里,我一直在为此而挣扎。我在windows机器上使用WAMP本地服务器,所以一切都在我的控制之下。在尝试导入Wordpress xml文件时,我得到了最长执行时间60秒的错误。

我已经在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);

我在进行更改后重新启动了服务器。我仍然得到错误

) Fatal error: Maximum execution time of 60 seconds exceeded in C:'wamp'www'xxa'wp-includes'wp-db.php on line 1285

谢谢Ahmar

这一定与硬编码的max_execution_time设置为60有关。

我对WordPress导入程序也有同样的问题。事实证明,这是因为wp-includes/functions.php文件中的硬编码@set_time_limit( 60 )

function wp_get_http( $url, $file_path = false, $red = 1 ) { @set_time_limit( 60 );

我评论了set_time_limit( 60 )调用,之后它运行良好:

//@set_time_limit( 60 );

当插件执行的初始检查耗时超过30秒时,可能会出现此问题。

请尝试其中一种:

  1. 调整wp-config.php:set_time_limit(60)

重要提示–如果您正在wp-config.php中进行更改,请在"/*仅此而已,停止编辑!博客快乐。*/"评论上方添加此行。

  1. 调整WordPress安装的/.htaccess文件php_value max_execution_time 60

  2. 调整php.ini文件max_execution_time=60;

最好在wp-config.php文件中进行更改。

如果这能解决问题,请告诉我。

感谢

我不得不自己测试register_shutdown_function()——我认为它不会运行。毕竟,一旦没有更多的内存,或者执行时间已经过去,用户函数怎么能运行呢?我惊讶地发现,关闭函数确实会运行,即使是在OOM的情况下,或者是在执行时间过长的情况下。概念证明:测试内存限制:

<?php
function asdf() { echo "omg'n"; }
register_shutdown_function('asdf');
ini_set('memory_limit', '1000');
$x = '';
while(true) {
 $x .= 'lkajsdlfkjasldkfjlaskdfjasldkfj';
}

输出:

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

测试执行时间:

cat scratch.php
<?php
function asdf() { echo "omg'n"; }
register_shutdown_function('asdf');
set_time_limit(1);
while(true) {}

输出:

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

请注意,要使您的消息在PHP的错误输出之前显示,您必须完全禁用PHP的错误输出。这是生产现场的最佳实践。