📜 ⬆️ ⬇️

Building and running HipHop-PHP


Almost three weeks ago , a new project from Facebook was announced . It is called HipHop-PHP.
For the general public, the source code became available only a day ago.

HipHop was created to improve the performance of Facebook. It converts PHP code to C ++ code and compiles it with g ++. HipHop is available under the opensource license.

This article describes the process of building HipHop from source codes and its use.
')

Assembly process


1. Clone the repository


$ git clone git: //github.com/facebook/hip-php

2. Install the necessary libraries


Install the required libraries listed in http://wiki.github.com/facebook/hiphop-php/building-and-installing . Check out the minimal versions.

Remarks:
  1. For TBB (Thread Building Blocks) minimum version 2.2, although it is not written
  2. Need to rebuild libcurl and libevent with patches from developers
    If you saw the message " struct evhttp_request has no member named ext_method" - it means that you have not patched libevent
  3. I also needed to install Google Perftools

3. Install the libmbfl library


$ cd hiphop-php
$ git submodule init
$ git submodule update

4. Set up environment variables


$ export HPHP_HOME = `pwd`
$ export HPHP_LIB = `pwd` / bin

5. Before assembly


HipHop build uses cmake . In the source script, some libraries were missing.
To fix this, install the patch:

$ curl sparcs.kaist.ac.kr/~tinuviel/hiphop/cmake-missing-library.diff | patch -p1

6. If you have a 32-bit system


HipHop was originally written for 64-bit architecture. If you have 32-bit, then you need to install patches:

$ curl sparcs.kaist.ac.kr/~tinuviel/hiphop/src-util-hash-long-long.diff | patch -p1
$ curl sparcs.kaist.ac.kr/~tinuviel/hiphop/src-cpp-base-ssize_t.diff | patch -p1
$ curl sparcs.kaist.ac.kr/~tinuviel/hiphop/src-lib-format-string.diff | patch -p1

7. Build


$ cmake.

and if there are no mistakes, then

$ make

Add-on for users of Debian, Ubuntu and others


The installation process is well described here , but do not forget the patches for the 32-bit system.

Launch


Let's create in the src / hphp folder an index.php file with contents
  1. < ? php
  2. echo 'Hello HipHop' ;
  3. ? >

Compile and run:
  $ time ./hphp index.php --keep-tempdir = 1 --log = 3
 running hphp ...
 creating temporary directory / tmp / hphp_71TLF1 ...
 parsing inputs ...
 parsing ./index.php ...
 parsing inputs took 0'00 "(6 ms) (null)
 pre-optimizing ...
 pre-optimizing took 0'00 "(0 ms) (null)
 inferring types ...
 inferring types took 0'00 "(0 ms) (null)
 post-optimizing ...
 post-optimizing took 0'00 "(0 ms) (null)
 creating CPP files ...
 creating CPP files took 0'00 "(213 ms) (null)
 compiling and linking CPP files ...

 compiling and linking CPP files took 1'30 "(90733 ms) (null)
 running executable / tmp / hphp_71TLF1 / program - file index.php ...
 Hello HipHopall files saved in / tmp / hphp_71TLF1 ...
 running hphp took 1'31 "(91747 ms) (null)

 real 1m31.791s
 user 1m21.157s
 sys 0m6.500s

The / tmp / hphp_71TLF1 folder contains quite interesting contents:
  $ ls -l / tmp / hphp_71TLF1 /
 total 25152
 -rw-r - r-- 1 20673 Feb 21 12:19 CMakeCache.txt
 drwxr-xr-x 6 4096 Feb 21 12:21 CMakeFiles
 -rw-r - r-- 1 1558 Feb 21 12:19 cmake_install.cmake
 -rw-r - r-- 1 2518 Feb 21 12:19 CMakeLists.txt
 -rw-r - r-- 1 18343 Feb 21 12:19 Makefile
 drwxr-xr-x 2 4096 Feb 21 12:19 php
 -rwxr-xr-x 1 25653366 Feb 21 12:21 program
 drwxr-xr-x 2 4096 Feb 21 12:19 sys
 $ ls -l / tmp / hphp_71TLF1 / php
 total 12
 -rw-r - r-- 1 783 Feb 21 12:19 index.cpp
 -rw-r - r-- 1 415 Feb 21 12:19 index.fw.h
 -rw-r - r-- 1 475 Feb 21 12:19 index.h

Contents of the /tmp/hphp_71TLF1/index.c file:

  1. #include <php / index.h>
  2. #include <cpp / ext / ext.h>
  3. namespace HPHP {
  4. ////////////////////////////////////////////////// /////////////////////////////
  5. / * preface starts * /
  6. / * preface finishes * /
  7. Variant pm_php $ index_php ( bool incOnce / * = false * / , LVariableTable * variables / * = NULL * / ) {
  8. FUNCTION_INJECTION ( run_init :: index . Php ) ;
  9. {
  10. DECLARE_GLOBAL_VARIABLES ( g ) ;
  11. bool & alreadyRun = g - > run_pm_php $ index_php ;
  12. if ( alreadyRun ) { if ( incOnce ) return true ; }
  13. else alreadyRun = true ;
  14. if ( ! variables ) variables = g ;
  15. }
  16. DECLARE_GLOBAL_VARIABLES ( g ) ;
  17. LVariableTable * gVariables __attribute__ ( ( __unused__ ) ) = get_variable_table ( ) ;
  18. print ( "Hello HipHop" ) ;
  19. return true ;
  20. } / * function * /
  21. ////////////////////////////////////////////////// /////////////////////////////
  22. }


As a result, the compiled program takes up as much as 25 megabytes.
But in addition to the console mode, it can be run in the web service mode:

/ tmp / hphp_71TLF1 / program -m server -p 8080

and see the greeting at localhost : 8080 / index.php

Update. Performance evaluation


Configuration


Processor: 2x Intel® Pentium® Dual CPU T2370 @ 1.73GHz
Operating System: Debian GNU / Linux squeeze / sid
Apache / 2.2.14 (Debian) with modphp
PHP 5.2.12-2 with Suhosin-Patch 0.9.7 (cli) (built: Jan 11 2010 17:30:06)
gcc version 4.4.3 20100108 (prerelease) (Debian 4.4.2-9)

Test number 1. "Head-on"


Running a test based on habratopika “Performance C ++ vs. Java vs. PHP vs. Python. Test "in the forehead"

 $ time php test.php 
 answer: 39

 real 0m32.308s
 user 0m32.258s
 sys 0m0.012s

 $ time / tmp / hphp_4C67mv / program - file test.php
 answer: 39

 real 1m6.683s
 user 1m6.376s
 sys 0m0.168s

 $ g ++ test.cpp 
 $ time ./a.out 
 answer: 39

 real 0m1.758s
 user 0m1.744s
 sys 0m0.000s

Test number 2. Apache benchmark


test.php:
  <? php
    for ($ i = 0; $ i <1000; $ i ++)
       echo var_dump ($ _ SERVER);
 ?> 


Running HipHop in web service mode:
  $ ./program -m server -p 8080
 $ ab -n 1000 -c 5 http://127.0.0.1:8080/test.php

 Concurrency Level: 5
 Time taken for tests: 67.019 seconds
 Complete requests: 1000
 Failed requests: 0
 Write errors: 0
 Total transferred: 1166084000 bytes
 HTML transferred: 1166000000 bytes
 Requests per second: 14.92 [# / sec] (mean)
 Time per request: 335.096 [ms] (mean)
 Time per request: 67.019 [ms] (mean, across all concurrent requests)
 Transfer rate: 16991.44 [Kbytes / sec] received

 Connection Times (ms)
               min mean [+/- sd] median max
 Connect: 0 0 0.1 0 2
 Processing: 124 335 56.5 340 477
 Waiting: 120 329 56.2 335 467
 Total: 124 335 56.5 341 477 


Run standard PHP using Apache with modphp:
 $ ab -n 1000 -c 5 http://127.0.0.1:80/test.php
 ...
 Concurrency Level: 5
 Time taken for tests: 27.180 seconds
 Complete requests: 1000
 Failed requests: 0
 Write errors: 0
 Total transferred: 1139183000 bytes
 HTML transferred: 1139000000 bytes
 Requests per second: 36.79 [# / sec] (mean)
 Time per request: 135.901 [ms] (mean)
 Time per request: 27.180 [ms] (mean, across all concurrent requests)
 Transfer rate: 40929.90 [Kbytes / sec] received

 Connection Times (ms)
               min mean [+/- sd] median max
 Connect: 0 0 0.5 0 11
 Processing: 52,136 32.2 137,216
 Waiting: 0 3 1.5 3 17
 Total: 52 136 32.2 137 216

Test number 3. Fractal benchmark


LanguageTimeRelative Speed
C gcc-4.4.30.05 seconds1.00 x
Hiphop0.18 seconds3.60 x
Python 2.512.35 seconds47.00 x
PHP 5.2.123.08 seconds61.60 x


Conclusions (personal opinion)


In two tests, it was almost twice as slow as standard PHP. But do not forget that this is just the first version. The HipHop build process itself is quite heavy, and as such there is no installation at all. You can install it only in order to understand the possibility of transforming your PHP application into C ++. The obvious minus of HipHop is the lack of support for PostgreSQL (so far only MySQL) and the inability to connect existing PHP modules. I hope that this project is still ahead.

That's all. More about the launch of HipHop can be read here .

Also on GitHub there are two interesting fork:
  1. http://github.com/h4ck3rm1k3/hiphop-php/ - contains add-ons to build deb-package
  2. http://github.com/sanxiyn/hiphop-php/tree/32bit - contains already installed patches for the 32-bit version

Source: https://habr.com/ru/post/85092/


All Articles