The road to php7

Preview:

Citation preview

The road to PHP7… by Luciano Giuseppe

2015

…the long road

Presentazioni

• Ciao! Sono Luciano Giuseppe

– Studente Magistrale di Informatica @UNISA

• Sito web: http://lgwebproject.it

> Perché v7 e non v6

• PHP 6 è il nome del branch di PHP chiuso nel 2010

– Doveva portare il supporto Unicode a tutte le istanze di testo

• PHPNG (PHP Next-Gen) è il branch alla base di PHP 7.

• Dopo 20 anni da PHP/FI 1 (Giugno 1995) viene rilasciato PHP 7

Miglioramenti di PHPNG

• Abstract Syntax Tree : “AST is an intermediate representation of the code during compilation. With this in place, we are able to clean up some edge case inconsistencies, as well as pave the way for some amazing tooling in the future, such as using the AST to produce more performant opcodes.”

• Uniform Variable Syntax: “the ability to call closures assigned to properties using ($object->closureProperty)()”

> Perché v7 e non v6 (ufficiosamente)

Facebook HHVM: • HipHop Virtual Machine (HHVM) è una virtual machine

basata su compilazione just-in-time (JIT) che funziona da motore di esecuzione per i linguaggi PHP e Hack. – Prima release pubblica: 2011

Cosa è cambiato? • Con la compilazione JIT, il codice PHP è prima trasformato

in codice intermedio HipHop bytecode (HHBC), che viene compilato in codice macchina e poi eseguito.

• PHP era un interprete: l’engine Zend trasformava il codice in opcode, il quale veniva eseguito direttamente dalla Zend Engine's virtual CPU lentuccio….

Ritorniamo a noi…

> PHP 7 - Nuovi internals • Bug fix

• Supporto pieno ai 64bit.

• Nuovo meccanismo di thread safety.

• Nuovo Memory management: nuovo heap ottimizzato

• Nuovo Executor: più veloce e meno memoria usata

“PHP is coming”: http://fr.slideshare.net/jpauli/php7-is-coming

> PHP 7 - Novità del linguaggio • Supporto Unicode(?) • Combined Comparison Operator • Null Coalesce Operator • Generatori • Scalar Type Declarations & Return Type • Classi Anonime • Group Use Declarations • Nuovo parser JSON • Funzioni deprecate rimosse • Retro-compatibilità

http://php.net/manual/en/migration70.new-features.php

Supporto Unicode (?)

• Le versioni di PHP7 rilasciate fin ora, non supportano ancora le stringe in unicode :

– Ustring è ancora in discussione dal gruppo PHP

– Si devono usare ancora le funzionalità di mbstring

• E’ stata implementato “Unicode Codepoint Escape”

– echo "\u{1F602}"; // outputs

https://wiki.php.net/rfc/ustring https://wiki.php.net/rfc/unicode_escape

Combined Comparison Operator

https://wiki.php.net/rfc/combined-comparison-operator

Null Coalesce Operator

Generatori

https://wiki.php.net/rfc/generator-delegation

Scalar Type Declarations

https://wiki.php.net/rfc/scalar_type_hints_v5

https://www.digitalocean.com/company/blog/getting-ready-for-php-7/

Classi Anonime

https://wiki.php.net/rfc/anonymous_classes

Group Use Declarations

https://wiki.php.net/rfc/group_use_declarations

Nuovo parser JSON

• Utile per usare i DB relazionali come document-oriented DB (NoSQL).

• MySql 5.7.7 (Aprile 2015) ha introdotto il tipo di dato JSON e le funzionalità per farci le query e manipolarli!

http://mysqlserverteam.com/json-labs-release-overview/

Funzioni deprecate rimosse

• Ereg (da PHP 5.3): usare pcre

• Mysql (da PHP 5.5): usare mysqli o pdo_mysql

• set_magic_quotes_runtime e magic_quotes_runtime (da PHP 5.4)

https://wiki.php.net/rfc/remove_deprecated_functionality_in_php7

Retro-compatibilità

Vi consiglio di leggere questo link:

http://php.net/manual/en/migration70.incompatible.php

Perché se scrivo $$foo['bar']['baz']

PHP5 capisce: ${$foo['bar']['baz']}

PHP7 capisce: ($$foo)['bar']['baz']

E altre sorprese …

> Cosa tener d’occhio

• Trait: come “ereditare” da più classi (da PHP 5.4)

• OPCache: OPcache improves PHP performance by storing precompiled script bytecode in shared memory, thereby removing the need for PHP to load and parse scripts on each request.

• Pthread: “For PHP7, pthreads has been almost completely rewritten to be more efficient, easier to use and more robust.”

• PHP.NET e FACEBOOK

OPCache

“OPCache main goal is to compile once and only once each PHP script, and cache the resulting OPCodes into shared memory, so that every other PHP worker of your production worker pool (usually using PHP-FPM) can make use of the OPCodes by reading then and executing then back.”

http://jpauli.github.io/2015/03/05/opcache.html

> Performance

• PHP.NET dice che con PHP7 :

– vi è un guadagno delle performance (rispetto a 5.6) tra il 20% e 110% su applicazioni come Wordpress, Drupal o SugarCRM.

– si consuma anche il 30% di memoria in meno.

• Google e Intel hanno dato una mano

https://docs.google.com/spreadsheets/d/1qW0avj2eRvPVxj_5V4BBNrOP1ULK7AaXTFsxcffFxT8/edit#gid=165039731

PHP vs PHP

http://talks.php.net/fluent15#/drupalbench

HHVM 3.7 vs PHP7 (Giugno 2015) Secondo Facebook

• Server Nginx e cache abiliata

http://hhvm.com/blog/9293/lockdown-results-and-hhvm-performance

Update Luglio 2015

• E’ stato rilasciato HHVM 3.8.0

https://www.zend.com/en/resources/php7_infographic

HHVM 3.7 vs PHP7 (Giugno 2015) Secondo ZEND

PHP vs Scripts

> Come faccio dei test miei?

• Virtual Machine con una distro Linux – Configurare un webserver con PHP: (si veda

http://build.prestashop.com/news/prestashop-1-6-1-0-performances/ )

• Attenzione a memory_limit nel php.ini: la massima memoria (RAM) utilizzabile dagli script

• Monitorare la RAM

• Controllare le richieste/sec: – Apache Benchmark

• ab -n 500 -c 100 -g out.data http://localhost/ – 100 richieste per 500 volte (attenti ai crash!)

– Siege:

– ….

> LINKS

• PHP.NET

• http://jpauli.github.io/

• http://www.phptherightway.com/

• http://www.phpbench.com/

Recommended