Re: Graceful timeout

From: Date: Sat, 16 May 2020 20:29:48 +0000
Subject: Re: Graceful timeout
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-110194@lists.php.net to get a copy of this message
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, https://amphp.org/ and it's Amp\Promise\timeout() / TimeoutCancellationToken might be helpful. Best, Niklas Am Sa., 16. Mai 2020 um 19:41 Uhr schrieb David Rodrigues < david.proweb@gmail.com>: > 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 >

« previous php.internals (#110194) next »