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?
Reply to discussion (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 ....
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
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 even timeout//analog timeout @c ();//error_reporting ($es) ;//Restore Set function Time_out_callback () { if (connection_status () = = 2) { B (); }} Function C () { //Your possible timeout code echo __function__, '; while (true) { echo '. '; Echo Connection_status (). "
";//echo 0 Usleep (100000);//Give CPU breath }}function B () { echo ')
' . __function__, "; Echo ' C Timeout connection status: '. Connection_status ();//echo 2,c Timeout}
PHP itself provides this type of functionality
Whether it is beautiful, you judge by yourself
Not all operations are calculated in PHP run time ...
Moderator to the force, Gray often beautiful, although the results are not very stable (change usleep value a result), PHP so the estimate is to the limit