the road to php7

30
The road to PHP7… by Luciano Giuseppe 2015

Upload: giuseppe-luciano

Post on 27-Jan-2017

1.472 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: The road to php7

The road to PHP7… by Luciano Giuseppe

2015

Page 2: The road to php7

…the long road

Page 3: The road to php7

Presentazioni

• Ciao! Sono Luciano Giuseppe

– Studente Magistrale di Informatica @UNISA

• Sito web: http://lgwebproject.it

Page 4: The road to php7

> 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

Page 5: The road to php7

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)()”

Page 6: The road to php7

> 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….

Page 7: The road to php7

Ritorniamo a noi…

Page 8: The road to php7

> 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

Page 9: The road to php7

> 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

Page 10: The road to php7

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

Page 11: The road to php7

Combined Comparison Operator

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

Page 12: The road to php7

Null Coalesce Operator

Page 13: The road to php7

Generatori

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

Page 14: The road to php7

Scalar Type Declarations

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

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

Page 15: The road to php7

Classi Anonime

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

Page 16: The road to php7

Group Use Declarations

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

Page 17: The road to php7

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/

Page 18: The road to php7

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

Page 19: The road to 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 …

Page 20: The road to php7

> 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

Page 21: The road to php7

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

Page 22: The road to php7

> 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

Page 23: The road to php7

PHP vs PHP

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

Page 24: The road to php7

HHVM 3.7 vs PHP7 (Giugno 2015) Secondo Facebook

• Server Nginx e cache abiliata

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

Page 25: The road to php7

Update Luglio 2015

• E’ stato rilasciato HHVM 3.8.0

Page 26: The road to php7

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

HHVM 3.7 vs PHP7 (Giugno 2015) Secondo ZEND

Page 27: The road to php7

PHP vs Scripts

Page 28: The road to php7

> 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:

– ….

Page 29: The road to php7
Page 30: The road to php7

> LINKS

• PHP.NET

• http://jpauli.github.io/

• http://www.phptherightway.com/

• http://www.phpbench.com/