【发布时间】:2012-04-19 00:48:28
【问题描述】:
According to the documentation:
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.
这已通过测试得到证实:
不会超时
<?php
set_time_limit(5);
$sql = mysqli_connect('localhost','root','root','mysql');
$query = "SELECT SLEEP(10) FROM mysql.user;";
$sql->query($query) or die($query.'<br />'.$sql->error);
echo "You got the page";
会超时
<?php
set_time_limit(5);
while (true) {
// do nothing
}
echo "You got the page";
我们的问题是,我们真的希望 PHP 超时,不管它在做什么,在给定的时间后(因为我们不想让资源保持忙碌,如果我们知道我们在可接受的时间量,例如 10 秒)。我们知道我们可以为 SQL 查询使用诸如 MySQL wait_timeout 之类的设置,但页面超时将取决于执行的查询数量。
有人尝试提出workarounds,但似乎无法实现。
问:有没有一种简单的方法可以在 linux 上获得真正的 PHP max_execution_time,或者我们最好在其他地方超时,例如 Apache 级别?
【问题讨论】:
标签: php mysql apache ubuntu timeout