Hi Aziz,
We thought about executing the evaluation in a subprocess and use the exit code to report errors. However, this approach has some performance penalties as it requires serializing the input context data and deserializing the result.
- Marcos
Thank you for your suggestion.
We will use it in an API, so good error reporting is a concern for us.
We will use it in an API, so good error reporting is a concern for us.
We thought about executing the evaluation in a subprocess and use the exit code to report errors. However, this approach has some performance penalties as it requires serializing the input context data and deserializing the result.
- Marcos
Em qua, 30 de out de 2019 às 09:15, Aziz Saleh <azizsaleh@xxxxxxxxx> escreveu:
On Wed, Oct 30, 2019 at 8:03 AM Marcos Passos <marcospassos.com@xxxxxxxxx> 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?
- MarcosIf 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.