Re: [PHP-DEV] Graceful timeout

This is only part of a thread. view whole thread
  110193
May 16, 2020 19:34 jakob@givoni.dk (Jakob Givoni)
On Sat, 16 May 2020 at 19:42, David Rodrigues proweb@gmail.com>
wrote:

> 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
Hi David! So you’d like to be able to set a simple timeout on any function call. I was able to do that with register_tick_function (first time I heard about it!) with a function that throws an exception when the time’s up and then surrounding the function call in try/catch. This could probably be turned into a userland “library”. I’m not sure how well it would work with real world code though. For sure, timeouts on http calls must be set on the client handler itself. Best, Jakob
> >