3. Presentazioni
• Ciao! Sono Luciano Giuseppe
– Studente Magistrale di Informatica @UNISA
• Sito web: http://lgwebproject.it
4. > 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
5. 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)()”
6. > 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….
8. > 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
9. > 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
10. 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
17. 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/
18. 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
19. 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 …
20. > 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
21. 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
22. > 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
28. > 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:
– ….