如何在PHP中处理mysql睡眠查询的异常?

I am using below sleep mysql query in PHP.

select sleep(50);

It takes 50 seconds to complete. PHP page is lading till that 50 seconds. Here I want to throw exception in PHP page. How can be achieved this ?

You can use set_time_limit(30) if you want to stop the script after 30 seconds and you can use register_shutdown_function() to handle the script exiting because of time expiration:

<?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;
?>