63

When I run composer --version in the macOS terminal, I get the following errors.

PHP Warning: preg_match(): JIT compilation failed: no more memory in phar:///usr/local/bin/composer.phar/vendor/symfony/console/Application.php on line 755

Warning: preg_match(): JIT compilation failed: no more memory in phar:///usr/local/bin/composer.phar/vendor/symfony/console/Application.php

on line 755 PHP Warning: preg_match(): JIT compilation failed: no more memory in phar:///usr/local/bin/composer.phar/vendor/symfony/console/Application.php on line 759

Warning: preg_match(): JIT compilation failed: no more memory in phar:///usr/local/bin/composer.phar/vendor/symfony/console/Application.php

on line 759 PHP Warning: preg_split(): JIT compilation failed: no more memory in phar:///usr/local/bin/composer.phar/vendor/symfony/console/Application.php on line 654

Warning: preg_split(): JIT compilation failed: no more memory in phar:///usr/local/bin/composer.phar/vendor/symfony/console/Application.php

on line 654 PHP Warning: preg_split(): JIT compilation failed: no more memory in phar:///usr/local/bin/composer.phar/vendor/symfony/console/Application.php on line 1091

Warning: preg_split(): JIT compilation failed: no more memory in phar:///usr/local/bin/composer.phar/vendor/symfony/console/Application.php

on line 1091 PHP Warning: preg_replace(): JIT compilation failed: no more memory in phar:///usr/local/bin/composer.phar/vendor/symfony/console/Formatter/OutputFormatter.php on line 36

Warning: preg_replace(): JIT compilation failed: no more memory in phar:///usr/local/bin/composer.phar/vendor/symfony/console/Formatter/OutputFormatter.php

on line 36

  [ErrorException]                                          
  preg_match_all(): JIT compilation failed: no more memory
Karl Hill
  • 12,937
  • 5
  • 58
  • 95
sheraz m
  • 666
  • 1
  • 5
  • 7
  • Hello there. We will need more information to really help you. First, it isn't clear that you are having a software development problem, which is really the purpose of this site (Stack Overflow, or "SO"). I'll assume your question fits since you're probably attempting PHP development/building with Composer. Next, we need to know how you're trying to install Composer, which version of PHP you have installed, etc. Finally, this post might help you: https://stackoverflow.com/questions/51656914/how-to-install-composer-on-macos – Greg T. Dec 09 '18 at 08:57
  • I don't have a fix for you but I encountered a similar problem. Downgrade to php 7.2. – Joe Niland Dec 09 '18 at 11:06

8 Answers8

144

This is a known PHP 7.3 bug, which has already been fixed.

As a temporary workaround, edit your php.ini file (in my case: vi /usr/local/etc/php/7.3/php.ini), disable PHP PCRE JIT compilation by changing:

;pcre.jit=1

to

pcre.jit=0
NikiC
  • 100,734
  • 37
  • 191
  • 225
Karl Hill
  • 12,937
  • 5
  • 58
  • 95
35

I solved this by disabling the PCRE jit compilation.

I suppose you installed php 7.3 through homebrew.

If so, create a zzz-myphp.ini in /usr/local/etc/php/7.3/conf.d with the following content:

; My php.ini settings
; Fix for PCRE "JIT compilation failed" error
[Pcre]
pcre.jit=0
fab120
  • 459
  • 4
  • 6
14

Other answers suggest disabling PCRE JIT via a configuration file. That works, but caveat: this disables PCRE JIT for all engine invocations that use those INI files. You therefore won't be getting JIT improvement for a potentially wider swath of functionality, which may not be desired.

You can disable JIT for composer only via:

php -d pcre.jit=0 composer.phar ...
bishop
  • 37,830
  • 11
  • 104
  • 139
3

In PHP 7.1.24 there is no 'pcre.jit' in php.ini file so you have to set memory_limit:128M (if you increase this).

Ashish Sharma
  • 446
  • 5
  • 14
3

It work for me by follow steps:

  1. Open you Terminal and run php --ini
  2. Open file php.ini in the path "Loaded Configuration File: /usr/local/php5/lib/php.ini" https://prnt.sc/p9tspy
  3. Find pcre.jit and change ;pcre.jit=1 to pcre.jit=0
0

Thanks for the answers.. I solved it by command composer.phar and then export path. Example:

$composer.phar
$export PATH=/usr/local/php5/bin:$PATH
$composer.phar --version
sheraz m
  • 666
  • 1
  • 5
  • 7
  • 1
    Is that explicitly telling composer to simply run on PHP 5.x? – Umbrella Dec 12 '18 at 18:19
  • @Umbrella Exactly. Its setting up a path for execution of composer. – sheraz m Dec 13 '18 at 01:27
  • Downgrading PHP also works, but is quite extreme. Perhaps invoking with `-d pcre.jit=0` or adding same to a configuration file would allow you to continue using version 7 without the trouble. – bishop Dec 14 '18 at 02:21
  • What happens when something you try to install via composer has php 7 as a requirement? Not to mention the fact that you're keeping a PHP version on your computer that is officially End-of-life. – Ben Hillier Jan 09 '19 at 14:32
-1

I got the same error. I installed MAMP 5.4 on my Mac OS 10.11.6 using PHP 7.3.7 and installed Composer. It seemed to work but as soon as I attempted to install Yii2 or even check the version, it gave me the error...

$composer.phar --version
Fatal error: Uncaught ErrorException: preg_match_all(): JIT compilation failed: no more memory in phar:///Users/kristin/Sites/htdocs/composer.phar/vendor/symfony/console/Formatter/OutputFormatter.php:137

Increasing the memory_limit in php.ini from 128M to anything did NOT solve the issue and pcre.jit=1 was commented out so turning it off didn't do anything either.

Here is what worked:

I simply changed the export path to the previous version's directory (without actually downgrading in MAMP's preferences) and it worked!

$export PATH=/Applications/MAMP/bin/php/php7.2.20/bin:$PATH
$composer.phar --version
Composer version 1.9.0 2019-08-02 20:55:32

If anyone can explain why this worked, I'd appreciate knowing. Cheers.

-1

This works for me -

  alias composer='php -d pcre.jit=0 /usr/local/bin/composer'

It's does not require and older version of PHP and is specific to composer. To persist across shell closure edit and add to ~/.bash_profile.

DanielM
  • 3,598
  • 5
  • 37
  • 53
ijf8090
  • 1
  • 2