Re: [PHP-DEV] Graceful timeout

This is only part of a thread. view whole thread
May 16, 2020 20:29 (Niklas Keller)
Hey David,

I guess you're looking for a preemptive timeout. I guess an alarm signal
and PHP's async signal handling will be your best bet here.

In case you're looking for a cooperative timeout, and
it's `Amp\Promise\timeout()` / `TimeoutCancellationToken` might be helpful.


Am Sa., 16. Mai 2020 um 19:41 Uhr schrieb David Rodrigues <>:

> Hello! > > Currently we can use set_time_limit() to specify that our script will run > by some seconds before we get "fatal error: maximum execution time of 1 > second exceeded". And we can't catch it and keep running. > > I believe that it is interesting to create a function that is able to limit > processing and stop when the time limit is recovered. > > $completeRun = set_time_limit_callback(function () { > sleep(2); > }, 1); > > var_dump($completeRun); > > Where $completeRun will be TRUE only if callback could run until it > returns, and FALSE if timeout. > > It should be very useful when we need works with external resources, like > RESTful, where timeout can occur and we need a better way to work with > that. Or when we have few seconds to run a process. > > What do you think? > > > Atenciosamente, > David Rodrigues >