How can I tell how to set the function execution time?
function A () {
//...
return true;
}
Function B () {
//...
return false;
}
Now start calling a ();
Imagine if a (), after 1.2 seconds did not return the result, immediately call B ();
What's the nice way to deal with it?
------Solution--------------------
Don't be too yourself, and don't make PHP any harder.
My solution
1, Ajax time-out interpretation disadvantage: Time is not accurate advantage: This feature can be temporarily implemented
2, PHP's C language extension disadvantage: The difficulty is big cost-effective not high advantage: time accurate efficiency high
3. Wait for Daniel ....
------Solution--------------------
Libevent can implement the function of the timer, but your a function should be to perform network tasks, if so, there must be a timeout setting
------Solution--------------------
PHP itself provides this type of functionality
Whether it is beautiful, you judge by yourself
Not all operations are calculated in PHP run time, you can verify it yourself
Register_shutdown_function ("Time_out_callback");
Set_time_limit (2);//Assuming 2 seconds to timeout
Analog timeout
@c ();
Error_reporting ($es);//Restore settings
function Time_out_callback () {
if (connection_status () = = 2) {
b ();
}
}
Function C () {
Your possible time-out code
echo __function__, ';
while (true) {
echo '. ';
Echo Connection_status (). "
";//echo 0
Usleep (100000);//give the CPU a breath
}
}
Function B () {
Echo '
' . __function__, ";
Echo ' C Timeout connection status: '. Connection_status ();//echo 2,c Timeout
}