SlideShare a Scribd company logo
1 of 30
Download to read offline
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/

More Related Content

Viewers also liked

Introduzione al linguaggio PHP
Introduzione al linguaggio PHPIntroduzione al linguaggio PHP
Introduzione al linguaggio PHP
extrategy
 

Viewers also liked (15)

A Practical Introduction to Symfony2
A Practical Introduction to Symfony2A Practical Introduction to Symfony2
A Practical Introduction to Symfony2
 
Introduzione pratica a Symfony
Introduzione pratica a SymfonyIntroduzione pratica a Symfony
Introduzione pratica a Symfony
 
PHP 7 - benvenuto al futuro
PHP 7 - benvenuto al futuroPHP 7 - benvenuto al futuro
PHP 7 - benvenuto al futuro
 
From * to Symfony2
From * to Symfony2From * to Symfony2
From * to Symfony2
 
Service approach for development Rest API in Symfony2
Service approach for development Rest API in Symfony2Service approach for development Rest API in Symfony2
Service approach for development Rest API in Symfony2
 
L'applicazione delle tecniche di data mining alla personalizzazione dei siti ...
L'applicazione delle tecniche di data mining alla personalizzazione dei siti ...L'applicazione delle tecniche di data mining alla personalizzazione dei siti ...
L'applicazione delle tecniche di data mining alla personalizzazione dei siti ...
 
Doctrine for Dummies
Doctrine for DummiesDoctrine for Dummies
Doctrine for Dummies
 
Symfony2 and AngularJS
Symfony2 and AngularJSSymfony2 and AngularJS
Symfony2 and AngularJS
 
Introduzione al linguaggio PHP
Introduzione al linguaggio PHPIntroduzione al linguaggio PHP
Introduzione al linguaggio PHP
 
PHP 7
PHP 7PHP 7
PHP 7
 
PHP 7 Crash Course - php[world] 2015
PHP 7 Crash Course - php[world] 2015PHP 7 Crash Course - php[world] 2015
PHP 7 Crash Course - php[world] 2015
 
Last train to php 7
Last train to php 7Last train to php 7
Last train to php 7
 
Symfony Best Practices
Symfony Best Practices Symfony Best Practices
Symfony Best Practices
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 

Similar to The road to php7

Pietro Brambati: PHP e la piattaforma Microsoft
Pietro Brambati: PHP e la piattaforma MicrosoftPietro Brambati: PHP e la piattaforma Microsoft
Pietro Brambati: PHP e la piattaforma Microsoft
Francesco Fullone
 
Web Services, le librerie Nusoap e PHP5 nell’interrogazione dei dati demograf...
Web Services, le librerie Nusoap e PHP5 nell’interrogazione dei dati demograf...Web Services, le librerie Nusoap e PHP5 nell’interrogazione dei dati demograf...
Web Services, le librerie Nusoap e PHP5 nell’interrogazione dei dati demograf...
Vincenzo Patruno
 

Similar to The road to php7 (20)

php day 2008 - Introduzione agli ez components
php day 2008 - Introduzione agli ez componentsphp day 2008 - Introduzione agli ez components
php day 2008 - Introduzione agli ez components
 
Php for ASP.NET Developers
Php for ASP.NET DevelopersPhp for ASP.NET Developers
Php for ASP.NET Developers
 
Pietro Brambati: PHP e la piattaforma Microsoft
Pietro Brambati: PHP e la piattaforma MicrosoftPietro Brambati: PHP e la piattaforma Microsoft
Pietro Brambati: PHP e la piattaforma Microsoft
 
Succo di lampone: come ottimizzare JAVA e PHP su un'architettura Raspberry Pi...
Succo di lampone: come ottimizzare JAVA e PHP su un'architettura Raspberry Pi...Succo di lampone: come ottimizzare JAVA e PHP su un'architettura Raspberry Pi...
Succo di lampone: come ottimizzare JAVA e PHP su un'architettura Raspberry Pi...
 
Codemotion 2014 : ottimizzare JAVA e PHP su un’architettura Raspberry Pi Cluster
Codemotion 2014 : ottimizzare JAVA e PHP su un’architettura Raspberry Pi ClusterCodemotion 2014 : ottimizzare JAVA e PHP su un’architettura Raspberry Pi Cluster
Codemotion 2014 : ottimizzare JAVA e PHP su un’architettura Raspberry Pi Cluster
 
Introduzione al PHP
Introduzione al PHPIntroduzione al PHP
Introduzione al PHP
 
Tanti "piccoli rilasci" con Symfony2
Tanti "piccoli rilasci" con Symfony2Tanti "piccoli rilasci" con Symfony2
Tanti "piccoli rilasci" con Symfony2
 
Php On Windows For Ph Pday 2008
Php On Windows For Ph Pday 2008Php On Windows For Ph Pday 2008
Php On Windows For Ph Pday 2008
 
High performance in Magento: HHVM
High performance in Magento: HHVMHigh performance in Magento: HHVM
High performance in Magento: HHVM
 
node.js everywhere
node.js everywherenode.js everywhere
node.js everywhere
 
Web frameworks
Web frameworksWeb frameworks
Web frameworks
 
Roma linuxday 2013 - nodejs
Roma linuxday 2013 - nodejsRoma linuxday 2013 - nodejs
Roma linuxday 2013 - nodejs
 
Profilazione di applicazioni PHP con XHProf.
Profilazione di applicazioni PHP con XHProf.Profilazione di applicazioni PHP con XHProf.
Profilazione di applicazioni PHP con XHProf.
 
Linux & Tools: per la piccola azienda e i freelance
Linux & Tools: per la piccola azienda e i freelanceLinux & Tools: per la piccola azienda e i freelance
Linux & Tools: per la piccola azienda e i freelance
 
Linux Embedded per l'automazione
Linux Embedded per l'automazioneLinux Embedded per l'automazione
Linux Embedded per l'automazione
 
Gaetano Giunta: eZ System PHP Inside
Gaetano Giunta: eZ System PHP InsideGaetano Giunta: eZ System PHP Inside
Gaetano Giunta: eZ System PHP Inside
 
Web Services, le librerie Nusoap e PHP5 nell’interrogazione dei dati demograf...
Web Services, le librerie Nusoap e PHP5 nell’interrogazione dei dati demograf...Web Services, le librerie Nusoap e PHP5 nell’interrogazione dei dati demograf...
Web Services, le librerie Nusoap e PHP5 nell’interrogazione dei dati demograf...
 
Grasso Frameworks Ajax
Grasso Frameworks AjaxGrasso Frameworks Ajax
Grasso Frameworks Ajax
 
Matteo baccan raspberry pi - linox 2014
Matteo baccan   raspberry pi - linox 2014Matteo baccan   raspberry pi - linox 2014
Matteo baccan raspberry pi - linox 2014
 
Dominopoint meet the experts 2015 - XPages
Dominopoint   meet the experts 2015 - XPagesDominopoint   meet the experts 2015 - XPages
Dominopoint meet the experts 2015 - XPages
 

The road to php7

  • 1. The road to PHP7… by Luciano Giuseppe 2015
  • 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
  • 24. HHVM 3.7 vs PHP7 (Giugno 2015) Secondo Facebook • Server Nginx e cache abiliata http://hhvm.com/blog/9293/lockdown-results-and-hhvm-performance
  • 25. Update Luglio 2015 • E’ stato rilasciato HHVM 3.8.0
  • 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: – ….
  • 29.
  • 30. > LINKS • PHP.NET • http://jpauli.github.io/ • http://www.phptherightway.com/ • http://www.phpbench.com/