# JIT Support for Regular Expressions

> Section in “New and Extended Functionality › Regular Expressions” of the book [PHP 7 Explained](https://php7explained.com/) by Sebastian Bergmann and Stefan Priebsch, published by thePHP.cc. The book covers PHP 7.0 to 7.4 and was last updated in November 2020. HTML version: <https://php7explained.com/new-and-extended-functionality/regular-expressions/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:

``` php
ini_set('pcre.jit', false);
```

---

Previous: [Regular Expressions](https://php7explained.com/new-and-extended-functionality/regular-expressions/index.html.md) | Next: [PCRE 2](https://php7explained.com/new-and-extended-functionality/regular-expressions/pcre-2/index.html.md)
