PHP 8 (imagen destacada)

Tiro monedas al aire, pero hasta ahora nunca las pude agarrar.

PHP 8 está planeado lanzarse en Diciembre 2020 y trae muchas novedades. La más interesante es JIT que vamos a mencionar lo que es en el post.

Obs:

  •  Utilizo Debian Buster de 64 bits.
  •  Hardware utilizado: 4 CPU, 6 GB de RAM, disco duro SSD 30 GB

Entramos a la terminal y tecleamos lo siguiente:

sudo apt update
sudo apt install git build-essential libgccjit-8-dev libzip-dev autoconf re2c bison libxml2-dev libsqlite3-dev
cd ~
mkdir repositoriosGit
cd repositoriosGit
git clone https://github.com/php/php-src.git
cd php-src
./buildconf
./configure --prefix=/opt/php/php8 --enable-opcache --with-zlib --enable-sockets --without-pear

Sale por pantalla:

+--------------------------------------------------------------------+
| License:                                                           |
| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE. By continuing this installation  |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+--------------------------------------------------------------------+

Thank you for using PHP

Volvemos a teclear en la terminal:

nproc

Sale por pantalla:

4

Obs:

  •  Como sale el número 4, en la próxima sentencia colocas el número en make -j4. 4 en nuestro caso, pero depende del número que te salga.

Volvemos a teclear en la terminal:

make -j4

Sale por pantalla:

Build complete.
Don't forget to run 'make test'.

Volvemos a teclear en la terminal:

make test

Obs:

  •  El proceso puede tardar bastante. Al terminar te pregunta si querés enviar tus resultados y si aceptas, te solicita tu mail.

Volvemos a teclear en la terminal:

sudo make install

Sale por pantalla:

Installing shared extensions:     /opt/php/php8/lib/php/extensions/no-debug-non-zts-20190128/
Installing PHP CLI binary:        /opt/php/php8/bin/
Installing PHP CLI man page:      /opt/php/php8/php/man/man1/
Installing phpdbg binary:         /opt/php/php8/bin/
Installing phpdbg man page:       /opt/php/php8/php/man/man1/
Installing PHP CGI binary:        /opt/php/php8/bin/
Installing PHP CGI man page:      /opt/php/php8/php/man/man1/
Installing build environment:     /opt/php/php8/lib/php/build/
Installing header files:          /opt/php/php8/include/php/
Installing helper programs:       /opt/php/php8/bin/
  program: phpize
  program: php-config
Installing man pages:             /opt/php/php8/php/man/man1/
  page: phpize.1
  page: php-config.1
/home/proyectosbeta/repositoriosGit/php-src/build/shtool install -c ext/phar/phar.phar /opt/php/php8/bin/phar.phar
ln -s -f phar.phar /opt/php/php8/bin/phar
Installing PDO headers:           /opt/php/php8/include/php/ext/pdo/

Ahora verificamos la versión del PHP. Volvemos a teclear en la terminal:

/opt/php/php8/bin/php -v

Sale por pantalla:

PHP 8.0.0-dev (cli) (built: Jun  7 2020 15:26:38) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies

La novedad más importante que trae PHP 8 es JIT (Just-In-Time).
El compilador JIT compilará el código fuente PHP en código de máquina para ejecutarlo, en vez de enviarlo a Zend VM para ser ejecutado. Así que ya no necesitamos un intérprete y el código funciona aún más rápido.

En PHP 8 para que funcione JIT se necesita tener OPcache.

PHP JIT se implementa como una parte casi independiente de OPcache. Se puede habilitar y deshabilitar en tiempo de compilación PHP y en tiempo de ejecución.

Volvemos a teclear en la terminal:

/opt/php/php8/bin/php --ini

Sale por pantalla:

Configuration File (php.ini) Path: /opt/php/php8/lib
Loaded Configuration File:         (none)
Scan for additional .ini files in: (none)
Additional .ini files parsed:      (none)

Volvemos a teclear en la terminal:

cd /opt/php/php8/lib
sudo nano php.ini

Agregamos:

zend_extension=opcache.so
opcache.enable=1
opcache.enable_cli=1
opcache.jit_buffer_size=32M
opcache.jit=1235

Guardamos el archivo (control + o) y luego cerramos en editor (control + x). Volvemos a teclear en la terminal:

/opt/php/php8/bin/php -v

Sale por pantalla:

PHP 8.0.0-dev (cli) (built: Jun  7 2020 15:26:38) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.0-dev, Copyright (c), by Zend Technologies

Ahora vamos a checkear JIT. Volvemos a teclear en la terminal:

cd ~
nano testJIT.php

Agregamos:

<?php
    for ($i = 0; $i <= 1000; $i++) {
        echo $i . ', ';
    }
?>

Guardamos el archivo (control + o) y luego cerramos en editor (control + x). Volvemos a teclar en la terminal:

/opt/php/php8/bin/php -d opcache.jit_debug=1 testJIT.php

Se ejecuta el script.
Sale por pantalla algo similar:

0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, JIT$/home/proyectosbeta/testJIT.php: ; (/home/proyectosbeta/testJIT.php)
	sub $0x10, %rsp
	lea 0x50(%r14), %rdi
	cmp $0xa, 0x8(%rdi)
	jnz .L1
	mov (%rdi), %rdi
	cmp $0x0, 0x18(%rdi)
	jnz .L8
	add $0x8, %rdi
.L1:
	test $0x1, 0x9(%rdi)
	jnz .L9
	mov $0x0, (%rdi)
	mov $0x4, 0x8(%rdi)
.L2:
	mov $EG(exception), %rax
	cmp $0x0, (%rax)
	jnz JIT$$exception_handler
	jmp .L6
.L3:
	cmp $0x6, 0x58(%r14)
	jnz .L11
	lea 0x60(%r14), %rdi
	lea 0x50(%r14), %rsi
	mov $0x427f8650, %rdx
	mov $zend_jit_fast_concat_helper, %rax
	call *%rax

Leyendo por varios sitio de internet, el JIT se va a notar  mucho cuando se haga machine learning, gráficos 2D/3D, etc

Esta versión esta en Alpha, así que ni se te ocurra utilizarla en producción.

Imagen destacada: Medium
Fuente: Arkadiusz Kondas


Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *