Re: Recovering from a hung regex
| From: | Alexandru Pătrănescu | Date: | Tue, 26 May 2020 14:39:32 +0000 |
| Subject: | Re: Recovering from a hung regex | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-327168@lists.php.net to get a copy of this message | ||
On Mon, May 25, 2020 at 8:09 PM Shivanand Sharma <shivanand@binaryturf.com>
wrote:
> So the script is a part of a web application / plugin which is basically a
> malware scanner.
>
> Webserver owners install this app and schedule it to run on a periodic
> basis.
>
> This means that it could be a LAMP or LEMP or other kind of stack with cgi
> or mod_php etc.
>
> Hang / Freeze: The issue is that some regexes / payloads or a combination
> thereof makes the script exceed max_execution_time. This is not desirable
> or even expected.
>
> In this case it's acceptable for the script to hit max_execution_time and
> the app will just schedule the next batch.
>
> However with the bug in question, the script exceeds max_execution_time
> and PHP has no way to recover.
>
> One way was to have a url-endpoint where we could post a request via curl
> and if that fails or times-out the script can still continue. But I was
> interested in exploring if PHP itself can recover from such a situation
> without having to rely on an external process.
>
> Regards,
> Shivanand Sharma
>
Hi Shivanand,
But external tools might be very simple and I think it would help here if
you run it as a separate process.
You can check https://www.man7.org/linux/man-pages/man1/timeout.1.html
that
it's easy to use.
Or you can implement a simple process runner with symfony/process from php
that would include your custom timeout logic, based in output of that
script maybe.
Regards,
Alex