2016-08-03 112 views

回答

1

您可以使用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; 
?> 
+0

腳本在30秒後未停止。其仍然載入50秒。 – selvan

+0

我正在使用mysqli_query($ link,「select sleep(50)」); – selvan

+0

弗朗茨,任何解決方案? – selvan