gpt4 book ai didi

PHP:set_time_limit() 似乎没有任何效果

转载 作者:可可西里 更新时间:2023-11-01 13:20:11 26 4
gpt4 key购买 nike

我试图在普通的 PHP apache 脚本(不是 CLI)中使用 PHP 的 set_time_limit() 来限制它的最大运行时间。它没有对系统调用或类似的东西做任何事情,我们没有使用安全模式(我们是服务器的所有者而不是管理员)。这是 Linux (Ubuntu) 上的 PHP 5.2.4。

简单的测试用例:

ini_set('max_execution_time', 1);
set_time_limit(1);
$i=0;
while ($i++<100000000000) {} // or anything other arbitrary that takes time
die('Done');

预期结果:与超出脚本执行时间有关

实际结果:打印完成。

我是不是做错了什么? (顺便说一句,是的,脚本确实需要并且可以运行太长时间并且需要中止,不幸的是,这不是可以避免的事情。这不是这里的重点。)

最佳答案

引用手册:

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() 是那些不影响脚本运行时间的函数之一

请参阅 MPHH 在手册的 sleep() 页面上的评论

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(), the sleep() function, database queries, etc. is not included when determining the maximum time that the script has been running.

关于PHP:set_time_limit() 似乎没有任何效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5484105/

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