PHP 8 with JIT. How it works?

Just-In-Time compilation

PHP 8 introduces two JIT compilation engines. Tracing JIT, the most promising of the two, shows about 3 times better performance on synthetic benchmarks and 1.5–2 times improvement on some specific long-running applications. Typical application performance is on par with PHP 7.4.

First you need to install docker and docker-compose.

Now let's create an opcache.ini file that will enable opcache and JIT in our container.

; Extended PHP.ini file to enable JIT.
; ====================================
; Place this file under /usr/local/etc/php/conf.d/
zend_extension=opcache.so
opcache.enable=1
opcache.enable_cli=1
opcache.jit_buffer_size=32M
opcache.jit=1235

Now we need to create a Dockerfile in the working folder.

FROM php:8.0-rc-cli

COPY opcache.ini /usr/local/etc/php/conf.d/

RUN apt-get update && apt-get upgrade -y \
    && apt-get install apt-utils -y \
#
#    install the necessary packages
    && apt-get install git zip vim libzip-dev libgmp-dev libffi-dev libssl-dev -y \
#
#    Enable required extensions
    && docker-php-ext-install -j$(nproc) sockets zip gmp pcntl bcmath ffi \
#
#    Extensions through pecl are put like this, then in php 8 pecl is now missing, so the lines are commented out
#    && PHP_OPENSSL=yes pecl install ev \
#    && docker-php-ext-enable ev \
#
#    Cleaning up temporary files
    && docker-php-source delete \
    && apt-get autoremove --purge -y && apt-get autoclean -y && apt-get clean -y

Creating docker-compose.yml file. 

version: '3.5'
services:
  php8-test:
    build: ./
    container_name: php8-test
    restart: unless-stopped
    volumes:
      - ./:/app
    working_dir: /app
    entrypoint: "php -S 0.0.0.0:8000"
    ports:
      - "127.0.0.1:8000:8000"
    logging:
      driver: "json-file"
      options:
        max-size: "1024k"
        max-file: "2"

Now you can run the container build.

docker-compose build

docker-compose up -d

docker-compose exec php8-test bash

Download benchmark file: github.com/php/php-src/blob/master/Zend/bench.php

Start benchmark:

php bench.php

Go and look what happen http://127.0.0.1:8000/.