Hi David, > You can probably implement this already with PHP's tick functionality (https://www.php.net/manual/en/function.register-tick-function.php), as > long as the code in the anonymous function does PHP statements/function > calls. > > If your problem is waiting for an external resource to be available > (database call, http call), then instead you should be able to use > functionality of these services to handle your timeouts.
If pcntl is available for your OS (not available on Windows), you can also use pcntl_async_signals() to allow receiving signals at any time, pcntl_alarm() to send a signal at a given number of seconds from then, and throw a custom exception from pcntl_signal() for SIGALRM. ticks() is limited - Every file would need to declare ticks=1 as of php 7.0, or you might get delayed in the files that didn't. Supporting a cross-platform form of pcntl_alarm() might be a better abstraction, but I don't have a strong use case for either of those. When implementing it, you'd need to ensure it didn't interfere with php's internal time limit implementations or signal handlers in an undesirable way (not something I'm deeply familiar with). That would also need to enable the checks that pcntl_async_signals(true) does. https://www.php.net/manual/en/function.pcntl-alarm.php https://www.php.net/manual/en/function.pcntl-async-signals.php https://www.php.net/manual/en/function.pcntl-signal.php - Tyson -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php