[英]How to handle exception for mysql sleep queries in PHP?
我在PHP中使用以下sleep mysql查詢。
select sleep(50);
需要50秒才能完成。 PHP頁面一直加載到50秒為止。 在這里,我想在PHP頁面中引發異常。 如何實現呢?
如果要在30秒后停止腳本,可以使用set_time_limit(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;
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.