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