"Allocation of JIT memory failed, PCRE JIT will be disabled" warning in PHP 7

c00000fd picture c00000fd · Dec 8, 2019 · Viewed 10.8k times · Source

I'm transitioning my website from PHP v.5 installed on a shared web-hosting account (at DreamHost) to run on PHP 7.3.11. After transition, I started noticing that once in a while I get these warnings:

Warning: preg_match_all(): Allocation of JIT memory failed, PCRE JIT will be disabled. This is likely caused by security restrictions. Either grant PHP permission to allocate executable memory, or set pcre.jit=0

The last one originated from this line of code that was supposed to replace special tags in my posted HTML for the page:

if(preg_match_all("/\[".$tagBegin."(\S)+\]/U", $html, $matches, PREG_OFFSET_CAPTURE) !== false)

Is there something that I need to do differently in v.7.3 to avoid that warning?

Answer

Alan H. picture Alan H. · Dec 12, 2019

You should be able to ward off this warning by using ini_set to change the config value suggested by the warning message itself:

ini_set("pcre.jit", "0");

Be sure to run that line of code before any usages of regular expressions.