Enable JIT in PHP 8.x OPcache - Rocketeers app

  [ Rocketeers ](/)   

[Login](https://rocketeersapp.com/login) 

 On this page

 Knowledge
---------

Enable JIT in PHP 8.x OPcache
=============================

### [\#PHP](https://rocketeersapp.com/knowledge/php)

Using OPcache can greatly improve \[PHP performance\](/php-performance). By enabling Just In Time (JIT) compiling in OPcache you can improve it even more.

 Published by [Mark van Eijk](https://rocketeersapp.com/author/mark-van-eijk) on November 21, 2024 
Updated on November 21, 2024 · 2 minute read

1. [What is JIT (Just In Time) compiling?](#content-what-is-jit-just-in-time-compiling)
2. [First: OPcache should be installed](#content-first-opcache-should-be-installed)
3. [How to enable JIT compiling](#content-how-to-enable-jit-compiling)
4. [Optimization level](#content-optimization-level)
5. [Enable in the CLI](#content-enable-in-the-cli)

[\#](#content-what-is-jit-just-in-time-compiling "Permalink")What is JIT (Just In Time) compiling?
--------------------------------------------------------------------------------------------------

JIT is a compiler optimization feature introduced in PHP 8 and can enable faster execution times for CPU intensive tasks. It enhances performance by translating frequently executed PHP code into machine code at runtime, allowing it to be executed directly by the CPU instead of being interpreted line-by-line. This results in significant speed improvements!

This is one of those extensions that's a bit confusing to setup, but it's not very dificult if you know how to.

[\#](#content-first-opcache-should-be-installed "Permalink")First: OPcache should be installed
----------------------------------------------------------------------------------------------

To begin with, we expect to have OPcache installed on your server. This is a PHP extension and on a Ubuntu server you can install it using (change to your current PHP version accordingly):

 ```
sudo apt install php8.4-opcache

```

[\#](#content-how-to-enable-jit-compiling "Permalink")How to enable JIT compiling
---------------------------------------------------------------------------------

By default JIT is disabled in OPcache, so you need to enable it manually. Also note that the enabling of OPcache is separate for the PHP (FPM) process and using PHP on the CLI.

JIT can be enabled by setting `opcache.jit_buffer_size` to a value and in general `128M` is a pretty decent value that's enough for most PHP applications. Add this line:

 ```
opcache.jit_buffer_size=128M

```

To your `php.ini` config file or in `/etc/php/8.4/mods-available/opcache.ini`:

 ```
opcache.enabled=1
opcache.jit_buffer_size=128M

```

Now JIT is enabled!

[\#](#content-optimization-level "Permalink")Optimization level
---------------------------------------------------------------

Next you need to decide a proper `opcache.jit` value that determines what optimizations the JIT compiler will perform. This can be precisely set as a bitmasker using a 4-digit integer "CRTO". More on this in the [PHP docs](https://www.php.net/manual/en/opcache.configuration.php#ini.opcache.jit).

But for typical usage, it's easier to use the following presets that cover most use cases. The following options:

 ```
# Completely disabled, cannot be enabled at runtime.
opcache.jit=disable

# Disabled, but can be enabled at runtime.
opcache.jit=off

# Use tracing JIT. Enabled by default and recommended for most users.
opcache.jit=on # or opcache.jit=tracing

# Use function JIT.
opcache.jit=function

```

For general usage you can choose `on` which is almost the highest setting (1254) to enable almost all optimization levels. This makes the config now:

 ```
opcache.enable=1
opcache.jit=on
opcache.jit_buffer_size=128M

```

[\#](#content-enable-in-the-cli "Permalink")Enable in the CLI
-------------------------------------------------------------

If you also want to optimize CLI usage, you can enable OPcache (and JIT) by adding:

 ```
opcache.enable_cli=1

```

### Subscribe to our newsletter

Do you want to receive regular updates with fresh and exclusive content to learn more about web development, hosting, security and performance? Subscribe now!

  Fill in your email address to receive updates  Subscribe 

#### More in [\#PHP](https://rocketeersapp.com/knowledge/php)

- [How to run PHP files](https://rocketeersapp.com/knowledge/run-php-files)
- [PHP file upload exceeds upload\_max\_filesize](https://rocketeersapp.com/knowledge/php-file-upload-exceeds-upload-max-filesize)
- [PHP Warning: Undefined array key](https://rocketeersapp.com/knowledge/undefined-array-key-php)
- [PHP Fatal error: Allowed memory size exhausted](https://rocketeersapp.com/knowledge/php-allowed-memory-size-exhausted)
- [PHP: Call to a member function on null](https://rocketeersapp.com/knowledge/call-to-a-member-function-on-null)
- [PHP Fatal error: Class "X" not found](https://rocketeersapp.com/knowledge/php-class-not-found)

 [View all 11 articles →](https://rocketeersapp.com/knowledge/php)
