如何解决 set_time_limit 不影响 PHP-CLI?
#!/usr/bin/php -q
<?php
set_time_limit(2);
sleep(5); // actually, exec() call that takes > 2 seconds
echo "it didn't work again";
最佳答案
max_execution_time
限制,这就是set_time_limit
设置、计数 (至少在 Linux 上) PHP 进程在工作时花费的时间。
引用 set_time_limit()
的手册页:
Note: The
set_time_limit()
function and the configuration directivemax_execution_time
only affect the execution time of the script itself.
Any time spent on activity that happens outside the execution of the script such as system calls usingsystem()
, stream operations, database queries, etc. is not included when determining the maximum time that the script has been running.
This is not true on Windows where the measured time is real.
当您使用 sleep()
时,您的 PHP 脚本不工作:它只是在等待...所以 没有考虑您等待的 5 秒max_execution_time
限制。
关于php - set_time_limit 不影响 PHP-CLI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2635002/