How can I determine the set function execution time? Function (){
//...
Return true;
}
Function B (){
//...
Return false;
}
Call ();
Imagine that if a () does not return results after 1.2 seconds, B () is immediately called ();
What are some beautiful solutions?
Reply to discussion (solution)
Don't be difficult for yourself or PHP
My solutions
1. Disadvantages of ajax timeout interpretation: time is not accurate enough. Advantage: This function can be implemented temporarily
2. Disadvantages of C language extension in PHP: difficult and cost-effective; advantages: accurate time and high efficiency
3. sit down and wait for the ox ....
Libevent can implement the timer function, but your a function should be used to execute network tasks. If yes, there must be a timeout setting.
Php itself provides such features
Pretty or not, you can judge by yourself
Not all operations are calculated in the php runtime. verify it by yourself.
Register_shutdown_function ("time_out_callback"); set_time_limit (2); // assume that a timeout occurs for 2 seconds. // The simulated timeout @ c (); // error_reporting ($ es ); // restore 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); // breathe the cpu} function B () {echo'
'. _ FUNCTION __, ''; echo 'c timeout connection status:'. connection_status (); // echo 2, c timeout}
Php itself provides such features
Pretty or not, you can judge by yourself
Not all operations are calculated in the php runtime...
The moderator is awesome and often pretty gray. although the results are not very stable (change the usleep value for a while), php's estimation has reached the limit.