Re: Running a code block with timeout

From: Date: Wed, 30 Oct 2019 12:15:05 +0000
Subject: Re: Running a code block with timeout
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-326931@lists.php.net to get a copy of this message
On Wed, Oct 30, 2019 at 8:03 AM Marcos Passos <marcospassos.com@gmail.com> wrote: > Hi everyone, > > We're looking for a way to run a code block with a timeout. > > Our use case involves evaluating an expression written in a custom DSL > (similar to Symfony Expression Language), and we want to ensure that the > execution will not exceed a given time limit. > > We tried a naive approach using set_time_limit, but there is no way to > catch the exception from the block code that timed out. We then considered > using PCNTL, but its use is discouraged production environments. > > Do you guys have any suggestions? > > - Marcos > If you don't care about the fatal error showing, you can catch the error using register_shutdown_function() method which will execute that function for you.

« previous php.general (#326931) next »