Hip Hop - gnulugperugia.org · Hip Hop Il compilatore PHP made in Facebook Linux Day 2010 Perugia...

Preview:

Citation preview

Hip HopHip Hop

Il compilatore PHP made in FacebookIl compilatore PHP made in Facebook

Linux Day 2010 ­ PerugiaLinux Day 2010 ­ Perugia

Paolo BernardiPaolo Bernardi

PHP the standard way 

Text + PHP

Parser

Bytecode

Zend Engine II

PHP the standard way 

Web Server

HTML request

HTML file

PHP request

PHP

PHP the cached way 

Il bytecode viene rigenerato ad ogni richiesta... È uno spreco!!!

Bytecode caching (es. APC)

PHP the cached way 

Se il sorgente PHP cambia troppo spesso il caching non è efficace

HipHop

2007, Haiping Zhao

PHP files

PHP the HipHop way

HipHop compiler

Web Server

PHP request

HTML file

HipHop compiler

PHP files

HipHop compiler

C++ files

Web server

C++ compiler

HipHop compiler

● Usa il g++

● Solo per x86_64

● Supporta PHP 5.2 (5.3 in progress)

● … salvo eval & co.

Funziona?

● ­50% CPU time per pagine web

● ­30% CPU time per API

Installazione (Ubuntu 10.10)

sudo apt­get install git­core cmake g++ 

libboost­dev libmysqlclient­dev libxml2­dev 

libmcrypt­dev libicu­dev openssl binutils­dev 

libcap­dev libgd2­xpm­dev zlib1g­dev libtbb­dev 

libonig­dev libpcre3­dev autoconf libtool 

libcurl4­openssl­dev libboost­system­dev 

libboost­program­options­dev libboost­

filesystem­dev wget memcached libreadline­dev 

libncurses­dev libmemcached­dev libicu­dev 

libbz2­dev

Installazione

A)mkdir hiphop

B)cd hiphop

C)git clone git://github.com/facebook/hiphop­

php.git

D)cd hiphop­php

E)export CMAKE_PREFIX_PATH=`/bin/pwd`/../

F)export HPHP_HOME=`/bin/pwd`

G)export HPHP_LIB=`/bin/pwd`/bin

H)git submodule init

I)git submodule update

J)cd ..

Installazione

A)wget http://www.monkey.org/~provos/libevent­

1.4.13­stable.tar.gz

B)tar ­xzvf libevent­1.4.13­stable.tar.gz

C)cd libevent­1.4.13­stable

D)cp ../hiphop­php/src/third_party/libevent­

1.4.13.fb­changes.diff .

E)patch ­p1 < libevent­1.4.13.fb­changes.diff

F)./configure ­­prefix=$CMAKE_PREFIX_PATH

G)make

H)make install

I)cd ..

Installazione (Ubuntu 10.10)

A)cd hiphop­php

B)cmake .

C)make

 … semplice, non è vero?

Utilizzo

A)$ cd .. 

B)$ export HPHP_HOME=`pwd`

C)$ export HPHP_LIB=`pwd`/bin

D)$ export CMAKE_PREFIX_PATH=$(pwd)/../

E)$ hphp/hphp test.php ­­keep­tempdir=1 ­­log=3

F)$ /tmp/hphp_p6vSsP/program ­m server ­p 8080

G)$ hphpi/hphpi ­f test.php

That's all, folks!That's all, folks!