0
我在PHP下面使用睡眠mysql查询。如何在PHP中处理mysql睡眠查询异常?
select sleep(50);
需要50秒才能完成。 PHP页面正在装载,直到50秒。这里我想在PHP页面中抛出异常。这怎么能实现呢?
我在PHP下面使用睡眠mysql查询。如何在PHP中处理mysql睡眠查询异常?
select sleep(50);
需要50秒才能完成。 PHP页面正在装载,直到50秒。这里我想在PHP页面中抛出异常。这怎么能实现呢?
您可以使用set_time_limit(30)
如果你想在30秒后停止脚本,您可以使用register_shutdown_function()
处理脚本退出,因为时间过期:
<?php
set_time_limit(30);
$script_finished = false;
register_shutdown_function('is_finished');
function is_finished(){
global $script_finished;
if(!$script_finished){
//Script got interrupted
echo "Oh, this script takes too much to complete!";
}
}
//Your code here
//...
//...
sleep(50); //For example
//Right before ending of php tag, script has ended
//Don't through is_finished function
$script_finished = true;
?>
脚本在30秒后未停止。其仍然载入50秒。 – selvan
我正在使用mysqli_query($ link,“select sleep(50)”); – selvan
弗朗茨,任何解决方案? – selvan