How To Enable & Use JIT Compiler In OpenLiteSpeed

How to enable JIT compiler

How to enable JIT compiler in OpenLiteSpeed servers ?

As you may be aware, PHP 8.0 introduced some exciting new features, one of which is the JIT compiler. You can quickly enable JIT compiler to improve the performance of your website. 

JIT stands for "Just in time," and it refers to the ability of PHP to compile its code straight into machine code (code that the CPU understands) without the use of an interpretation layer. A JIT compiler in PHP provides significant performance advantages for CPU-intensive operations. 

The JIT depends on the opcache to function so the steps actually are for configuring opcache in your server. 


Step 1

To begin, add the following lines to your main php.ini file: /usr/local/lsws/lsphp80/etc/php/8.0/litespeed/php.ini if you are using openlitespeed server. In this case, I'm editing the php.ini file with nano.

nano /usr/local/lsws/lsphp80/etc/php/8.0/litespeed/php.ini +1766
Please keep in mind that '+1766' is the line number in my example where the opcache setting is applied. You can alter the values of jit buffer size and other variables on your own to meet the needs of your application.

opcache.enable=1

; Determines if Zend OPCache is enabled for the CLI version of PHP
opcache.enable_cli=1
opcache.jit_buffer_size=256M
opcache.jit=1235
If you have enabled opcache, the first lines should be present in your php.ini file, if not, you can uncomment or add them. If you haven't already installed opcache, run the following command to do so.

apt install lsphp80-opcache
How to enable JIT compiler

Step 2

So back to our topic, once you've done the modifications listed above, we need to restart the lsws service as shown below.

service lsws-rc restart

Step 3

We can confirm the result using either the terminal or the browser. We only need to run the following line from the terminal:

/usr/local/lsws/lsphp80/bin/php -i | grep -i JIT
It will show result as below
How to enable JIT compiler
You can confirm this by including an PHP info page. 

Notes

We encountered various challenges while configuring this topic, so I hope this essay can assist you in similar scenarios. 

The value of "opcache.jit buffer size" is set to 0 by default, indicating that the JIT is turned off. As a result, bigger values, such as 256M, are required to enable JIT. 

Second, it appears that some extensions, such as the newrelic extension, deactivate JIT. You are likely to run into this issue if you utilise the newrelic extension. Disable newrelic extention and check the status once again. 

I hope this has been helpful in this matter, and do let us know if you have any more questions.


Comments