Improving PHP performance - Rocketeers app

  [ Rocketeers ](/)   

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

 On this page

 Knowledge
---------

Improving PHP performance
=========================

### [\#Hosting](https://rocketeersapp.com/knowledge/hosting)

The performance and speed of PHP can be improved in different ways. Find out the multiple pathways to better performance.

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

1. [Enable OPcache](#content-enable-opcache)
2. [Enable OPcache JIT compiler](#content-enable-opcache-jit-compiler)

[\#](#content-enable-opcache "Permalink")Enable OPcache
-------------------------------------------------------

Using the OPcache PHP extension is one of the most significant (and easy) things you can do to improve PHP performance. When a PHP script runs, the server translates the script into a form the computer can understand (called "opcode") every time someone visits the website. This process takes time. With the OPcache extension enabled thee translated version (opcode) is stored in memory, so the server doesn’t have to re-translate the script every time. Instead, it reuses the stored version, making the website load faster.

 ```
# Install OPcache extension (change PHP version accordingly)
sudo apt install php8.4-opache

# Enable it in php.ini
opcache.enable = 1
opcache.enable_cli = 1
opcache.max_accelerated_files = 50000
opcache.interned_strings_buffer = 64
opcache.memory_consumption = 256
opcache.save_comments = 1
opcache.validate_timestamps = 1

```

If you change `opcache.validate_timestamps` to `0` you can improve performance even more because OPcache does not need to check the file for modifications everytime. But then you will need to make sure you reload the PHP process every time you make changes in your code.

[\#](#content-enable-opcache-jit-compiler "Permalink")Enable OPcache JIT compiler
---------------------------------------------------------------------------------

After enabling OPcache, you should also consider enabling the [OPcache JIT compiler](/php-8-opcache-jit). It enhances performance by translating frequently executed PHP code into machine code at runtime, meaning running even more efficient on your server.

Enable JIT by adding these lines to the OPcache config:

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

```

### 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 [\#Hosting](https://rocketeersapp.com/knowledge/hosting)

- [How to get top processes with highest memory usage](https://rocketeersapp.com/knowledge/top-processes-memory)
- [How to get top processes with highest CPU usage](https://rocketeersapp.com/knowledge/top-processes-cpu)
- [How to add Swap Space on Ubuntu servers](https://rocketeersapp.com/knowledge/add-swap-space-on-ubuntu)
- [Disable unnecessary and unused PHP versions (FPM pools)](https://rocketeersapp.com/knowledge/disable-unused-php-fpm-pools)
- [Reclaim disk space on Ubuntu server](https://rocketeersapp.com/knowledge/reclaim-diskspace-on-ubuntu)
- [How to check Ubuntu version](https://rocketeersapp.com/knowledge/ubuntu-version)

 [View all 16 articles →](https://rocketeersapp.com/knowledge/hosting)
