2016-08-03 111 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