JIT Support for Regular Expressions
To speed up processing of regular expressions, starting with PHP 7 the JIT – the just-in-time compilation – of the underlying PCRE library has been enabled. What sounds like a good idea comes with a potential drawback: Given a rather complex and potentially inefficient regular expression applied against a longer input value, the JIT compiler may hit the configured stack size limit.
To verify if the execution hit against any limit, or some other
error occurred, the PHP function preg_last_error()
can
be used. For the stack limit error, PHP 7 adds the
PREG_JIT_STACKLIMIT_ERROR
constant as a potential
return value.
As that configuration is a compile-time setting, currently the
only workarounds are to either simplify the regular expression or to
disable the JIT. This can be done in php.ini
or using
ini_set()
at runtime:
ini_set('pcre.jit', false);