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

5

12

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?

Quisling answered 8/12, 2019 at 1:44 Comment(2)
There's a bug filed here. I think it's related to your issue.Eleusis
There's no bug in PHP (there have been other PHP PCRE JIT bugs) but @c00000fd's issue is not a bug. PHP tries to get executable memory for the PCRE JIT and is blocked by Dreamhost's configuration (I think because /tmp is mounted noexec, Dreamhost doesn't appear to use SELinux, in any case the reason isn't important). PHP then displays this message, falls back to non-JIT PCRE, and continues processing with the JIT disabled. That's why this message only appears sometimes and pages otherwise appear normal. The fix is to put pcre.jit=0 into php.ini, see my comment on that answer below.Pinwheel
I
12

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.

Interpose answered 12/12, 2019 at 7:12 Comment(5)
None of above, should be ini_set('pcre.jit, '0') as both arguments are expected to be of string type.Enlargement
This is a bad work-around, not solving the actual issue. The key is: "grant PHP permission to allocate executable memory."Proposal
I’m going to charitably rephrase your comment, with some guesses and assumptions: “This is a fine work-around, but to get better performance out of regular expression matching, it would be even better to grant PHP permission to allocate executable memory. This allows the JIT system to run, as opposed to this work-around, which simply disables Regex JIT compilation. OTOH, there may be security arguments for keeping JIT off. Given a shared hosting environment, the choice may not really be yours to make, in the end!”Interpose
@Proposal can you give your answer as to how to "grant PHP permission to allocate executable memory." ?Fricandeau
Recent versions of PHP, systemd, and selinux impose limits and security blocks on access or dynamic allocation of system resources by things like PHP (and php-fpm). For production purposes, the most secure setting is to disable it in your .ini config (pcre.jit=0), however if you want to "unblock" it from selinux: setsebool -P httpd_execmem on Ref: serverfault.com/questions/991549/…Masseur
P
4

For me I have added pcre.jit=0 to php.ini file in [Pcre] and this worked very nice.

Pearly answered 3/1, 2020 at 12:56 Comment(2)
Where are you supposed to put that php.ini -- the root folder or the same folder where .php script is located? Because it doesn't seem to do anything in my case. (Again, I'm doing it on a shared web hosting account, so I don't have access to everything.)Quisling
@c00000fd, Dreamhost has got a special file layout you should use for their shared hosting accounts. Add that line to ~/.php/7.3/phprcPinwheel
F
4
  1. Search in whatever system manages your website : the cPanel's File Manager, your web hoster's admin dashboard, your computer's disks- for 'php.ini'. There won't be many files named like that in places that have something to do with your website or application that is giving you an error message.

  2. Edit that php.ini file and find the section [Pcre] and add this line at the bottom of that section : pcre.jit=0

It should look something like this: enter image description here

  1. Save your changes and reload the page or application.
Fricandeau answered 5/9, 2020 at 4:32 Comment(1)
setting pcre.jit=0 is disallowing pcre to use JIT, NOT granding PHP permission on executable memory. Granting permission should be done through setsebool becuase it is blocked by selinux.Saltworks
E
0

Open your php.ini file (C:\xampp\php\php.ini) and search for this setting:

;Enables or disables JIT compilation of patterns. This requires the PCRE
;library to be compiled with JIT support.
;pcre.jit=1

Remove the comment and make sure that it is set to 1:

pcre.jit=1

Restart your Apache server and the warning will go away with the correct permission set.

Elisavetpol answered 21/7, 2022 at 10:0 Comment(0)
E
0

I have Xampp and a previous version of PHP. I fixed that error by following a video on Youtube called :

PhpMyAdmin Error Warning in .\libraries\classes\Config\FormDisplay.php#

basically what he did is he went in the button of PHPAdmin page and downloaded a new version, then he made the config file inside PHPAdmin folder(in Mac) and deleted all files then pasted the new files of the new PHP admin along with the config. It worked great for me and him.

Etoile answered 9/2, 2023 at 19:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.