On Wed, Mar 1, 2017 at 4:35 PM, Rasmus Schultz <rasmus@mindplay.dk> wrote:
> Hey internals,
>
> I was wondering whether or how PCRE regular expression get parsed and
> cached, and I found this answer on Stack Overflow:
>
> http://stackoverflow.com/questions/209906/compile-regex-in-php
>
> Do I understand this correctly, that:
>
> 1. All regular expressions are hashed and the compiled expression is cached
> internally between calls.
>
Correct.
2. The /S modifier applies more optimizations during compile, but caching
> works the same way.
>
Yes. Additionally, if PCRE JIT is enabled (which it usually is on PHP 7) we
always study, independently of whether /S was specified.
> 3. Compiled expressions are not cached between requests.
>
Compiled expressions are cached between requests. However, they are not
shared between processes (I'm not even sure if that's possible.)
The cache invalidation strategy is FIFO. More specifically, whenever the
cache fills up, we discard the first 1/8 cached regular expressions.
Nikita