11

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?

c00000fd
  • 20,994
  • 29
  • 177
  • 400
  • 1
    There's a bug filed [here](https://bugs.php.net/bug.php?id=78630). I think it's related to your issue. – Rain Dec 11 '19 at 02:08
  • 2
    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. – joelhardi Feb 18 '20 at 18:38

5 Answers5

11

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.

Alan H.
  • 16,219
  • 17
  • 80
  • 113
  • None of above, should be `ini_set('pcre.jit, '0')` as both arguments are expected to be of `string` type. – Mike Doe Dec 12 '19 at 07:41
  • 3
    This is a bad work-around, not solving the actual issue. The key is: "grant PHP permission to allocate executable memory." – hackel May 05 '20 at 19:25
  • 5
    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!” – Alan H. Jun 15 '20 at 04:50
  • 3
    @hackel can you give your answer as to how to "grant PHP permission to allocate executable memory." ? – Splambo Sep 05 '20 at 02:09
  • 3
    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: https://serverfault.com/questions/991549/grant-php-permission-to-allocate-executable-memory – Danang Ponorogo Jul 20 '21 at 23:49
4

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

Ruberandinda Patience
  • 3,435
  • 3
  • 20
  • 18
  • 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.) – c00000fd Jan 03 '20 at 20:48
  • 2
    @c00000fd, Dreamhost [has got a special file layout](https://help.dreamhost.com/hc/en-us/articles/214200688-php-ini-overview) you should use for their shared hosting accounts. Add that line to `~/.php/7.3/phprc` – joelhardi Feb 18 '20 at 18:23
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.
Splambo
  • 144
  • 1
  • 13
  • 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. – Quickpick Dec 21 '21 at 21:29
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.

RGriffiths
  • 5,722
  • 18
  • 72
  • 120
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.

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175