Troubleshooting PHP JIT: A Definitive Guide to Enabling Performance Boost When Configuration Fails
Many posts online suggest that enabling PHP JIT is as simple as adding some values to the php.ini file, but that's not exactly the case. Sometimes adding these configuration values doesn't seem to do anything. In this post, I'll show how to enable PHP JIT when nothing seems to work. I'll use a default Laravel Sail Docker container, but the idea is the same for any server running PHP.
1. Check if a PHP extension is blocking JIT from loading. Type this command in the terminal to see JIT status:
./vendor/bin/sail php -r "print_r(opcache_get_status(false)['jit']);"
If you see this warning, then a PHP extension is blocking JIT:
PHP Warning: JIT is incompatible with third-party extensions that override zend_execute_ex(). JIT disabled. in Unknown on line 0.
2. Disable problematic extensions. Laravel Sail Docker file installs many extensions, so we need to identify which ones are not compatible with PHP JIT. After disabling extensions one by one, I found that php8.3-pcov and php8.3-xdebug are problematic.
To disable these extensions:
- Ensure your .env file doesn't have SAIL_XDEBUG_MODE or any other environmental values that enable xDebug
- Add these values to your php.ini:
pcov.enabled=0
xdebug.mode=off
Also, add these values to enable JIT:
[opcache]
zend_extension=opcache.so
opcache.enable=1
opcache.enable_cli=1
opcache.memory_consumption=128M
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.jit_buffer_size=100M
opcache.jit=tracing
3. Restart If you're using Laravel Sail, rebuild your image with:
sail down
sail build
sail up -d
Execute the command again to verify if JIT is properly enabled:
./vendor/bin/sail php -r "print_r(opcache_get_status(false)['jit']);"
And that's it. Hopefully, your PHP JIT is now enabled and working.