In an earlier article I described how to install HipHop for PHP translator that allows compilation of the PHP scripts.
This time, I will describe different types of compilations, so that it is possible to build both simple scripts and large systems written in PHP.
In this article I assume that the installation of HH has already been successfully completed, and all the system path set correctly.
If HH is not yet installed, read the installation instructions, which I put in this entry.
How to compile simple PHP script?
In this case, just type a simple command from the console. Assuming that the PHP file is located in /foo/bar/ directory, and the HipHop translator is in /root/hiphop/hiphop-php/ directory, the command would look like this:
/root/hiphop/hiphop-php/src/hphp/hphp /foo/bar/script.php –keep-tempdir=1 -o /tmp/test
This will translate, compile, and execute a compiled PHP script in the CLI mode. All generated binary/C++ files will be stored in the /tmp/test directory, so you can easily execute the script again, using following command:
How to compile complex PHP project?
In this case, you must create a list of PHP files that belong to the project and which must be compiled.
find /foo/bar/ -name "*.php" > files.list
After building a list, you can run the build with the following command:
cd ~drupal /root/hiphop/hiphop-php/src/hphp/hphp --keep-tempdir=1\ --input-list=files.list\ --include-path="." \ -o /tmp/test\ --parse-on-demand=1\
Just as in the case of a simple script, also here the project will be started automatically after compilation.
Also in this case, you can run the project again by typing:
How to run compiled project in web server mode?
To run the project in web server mode, you must issue the following command:
/tmp/test/program -m server -p 80
This will launch compiled project as a server listening on a default HTTP port. Please note however, that in order to be able to bind to a port below 1024 you will need to have root privileges.
If you want to run your PHP scripts without root privileges, you will have to change the port number accordingly.
If you have any questions…
Please report them in comments to this article. I’ll try to answer all of them.