gpt4 book ai didi

php - set_time_limit 不影响 PHP-CLI

转载 作者:IT王子 更新时间:2023-10-28 23:58:19 27 4
gpt4 key购买 nike

如何解决 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 directive max_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 using system(), 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com