HipHop PHP实战(详解web运行模式)

Note: These code examples assume the HipHop compiler is fully built.

1 . Setting Up Your Environment (构建环境)

To get started, you need to configure two environment variables.

cd .. # into the root of the hphp checkout  
export HPHP_HOME=`pwd`  
export HPHP_LIB=`pwd`/bin  
# if you followed the Ubuntu 9.10 instructions, you also need  
export CMAKE_PREFIX_PATH=`/bin/pwd`/../

2 . Choosing which Mode to Run HipHop  (HipHop运行模式)

You can run HipHop in 5 different modes. These Hello World examples demonstrate each one. All commands are run from the src/ directory in these examples.

First, create a file called test.php. Populate it with some text, like, “echo Hello, World! > test.php”. Then choose from the following modes:

  Mode 1 (直接运行模式 ): Compiling HipHop and running it directly.  

echo "Hello, World!" > test.php  
hphp/hphp test.php

   Mode 2 (命令行运行编译程序  ): Compiling HipHop in a temporary directory and running the compiled program from the command line. 

hphp/hphp test.php --keep-tempdir=1 --log=3  
/tmp/hphp_p6vSsP/program    (use your own temporary directory name from output)

--keep-tempdir=1 can also be specified with -k 1. Note it’s single dash and there is a space, not “=” between “k” and “1”. This is something to watch out when working with boost command line options.

--log=3 outputs some verbose information, so you can find out which temporary directory it created. You may always specify your own output directory with --output-dir=mypath or -o mypath.

   Mode 3 (使用web 运行编译模程序 ): Compiling HipHop in a temporary directory and running the compiled program as a web server.

hphp/hphp test.php --keep-tempdir=1 --log=3  
sudo /tmp/hphp_p6vSsP/program -m server

Then, from another window, run:

curl localhost/test.php

If you don’t want to use sudo, you can run HipHop on port 8080.

hphp/hphp test.php --keep-tempdir=1 --log=3  
/tmp/hphp_p6vSsP/program -m server -p 8080  
curl http://localhost:8080/test.php

Run this command to administer your server:

curl http://localhost:8080

You can also run the server as a daemon:

sudo /tmp/hphp_p6vSsP/program -m daemon

  Mode 4 (直接解释运行): Interpreting HipHop directly.

hphpi/hphpi -f test.php  (note the "-f" flag)

Mode 5 (web服务器运行源代码): Starting a Web server or daemon and interpreting HipHop on the fly.

sudo hphpi/hphpi -m server (or daemon)  
curl localhost/test.php  
curl localhost:8088

说明:
curl localhost/test.php其实就是客户端浏览器访问模式,好多人都问hiphop怎么和web服务器结合?  

我们前面安装了库libevent。而PHP也能直接使用libevent构建web服务器.

其实HipHop可以当作web服务器来运行,说白了hphpi/hphpi -m server就是监听个端口守护进程,默认是80端口。

命令

我的安装目录是/opt/hiphop/hiphop-php/

如图:

1.jpg

1)sudo src/hphpi/hphpi -m server相当apache的守护进程启动,并监听80端口。

2)目录/opt/hiphop/hiphop-php/相当于apache的web根目录  

3)在这个目录下可以新建文件

      test.php,内容如下:

2.jpg

    使用浏览器访问:

3.jpg

    再新建test文件夹,

   cp  test.php   test/ 

    访问结果:

    4.jpg

3. Compiling a Large Codebase (编译代码库)

First, familiarize yourself with the various of switches of the compiler:

hphp/hphp --help

There are 3 ways to specify some flags. 

(1) by a configuration file in HDF format. Please read doc/hdf for more details with the format. Then use--config to specify the config file. 

(2) For almost every option in HDF file, you can list it directly in its dot notation format. For example,-v "node.subnode=value"

(3) We created some shortcuts for most frequently used ones. They will look like --force.

The most important flags to learn are the ones for including or excluding files and directories. They were not designed cleanly and we may have to improve the way how they work. When in doubt, simply use the --input-list switch to take a list of file names prepared in a separate file.

You can get all the possible flags here: Runtime options

Using Parse-on-demand Mode (optional)

You can include files that are not specified from the command line into the compilation only if the compiler can determine where to find them. This means your include statements themselves are either:

  • Formed by simple literals; so the compiler can compute them during compilation time.

  • Written in simple form like "include_once $MY_ROOT.'/path/file.php';"
    Note: You can tell the compiler where to look for $MY_ROOT by creating a configuration file with content like this:

IncludeRoots {  
  * {  
    root = $MY_ROOT  
    path = lib/my_code  
  }  
  * {  
    root = $ANOTHER_ROOT  
    path = anotherlib  
  }  
}

Use --config to include this configuration file. The compiler resolves the above include statement as “lib/my_code/path/file.php”.

Note: If you find parse-on-demand mode difficult to configure, try using --input-list to include every PHP file you want to compile.

Using distcc

For large compilations, we recommend setting up distcc.

4 . Example: Compiling PHPUnit

1. Check out PHPUnit’s PHP files:

git clone git://github.com/sebastianbergmann/phpunit.git  
cd phpunit  
git checkout -b 3.4 origin/

2. We will use the safest and the cleanest way to specify input files,

find . -name "*.php" > files.list

This prepares a list of all PHP files we want to compile.

3. Now we’re ready to compile the project.

$HPHP_HOME/src/hphp/hphp --input-list=files.list -k 1 --log=3 \  
  --include-path="." --force=1 --cluster-count=50 \  
  -v "AllDynamic=true" -v "AllVolatile=true"

-k 1 or --keep-tempdir=1 so it creates a new temporary directory every time. This is convenient when you’re experimenting the compilation.

The --include-path is needed, because PHPUnit has file includes relative to root directory of phpunit. Without specifying this option, all includes in a format of “include ‘somepath/file.php’;” will be treated as relative path to the containing file.

--force=1 is needed to ignore warnings and errors HipHop found in the code. Without this option, the compiler will halt and dump out the errors on the screen, if any. With --force=1, those errors will mostly turn into run-time ones, and you may still find them in CodeError.js generated under the output directory.

--cluster-count=50 helps compilation, with or without distcc. Without this flag, each PHP file generates one .cpp file. When the number of PHPfiles is large, we may end up with too many .cpp files to compile. With clustering, no matter how many PHP files we have, HipHop will generate roughly the specified number of .cpp files, so it’s easier to feed them into distcc with fewer rounds. What we found is, cluster count should be slightly smaller than number of distcc workers. For example, if you have 20 machines each with 8 distcc workers, cluster count of 100 may be suitable. But one should change the numbers up and down to compare compilation time to find out the optimal value.

-v "AllDynamic=true" With this option, we can support dynamic function calls and dynamic method calls without any problems. Recommended to turn on, if coding has them. It will sacrifice performance a little bit, but it’s safe to have it.

-v "AllVolatile=true" With this option, we can support dynamic declarations of functions and classes without any problems. This is not recommended to turn on, unless your coding has crazy testing of function_exists() or class_exists() before or after declarations and the order is meaningful. PHPUnit happens to call get_declared_classes() before and after loading some class files and compare their returns to find new classes. Therefore, we need to add this switch to PHPUnit. Most likely, you don’t have to. It sacrifices performance in various degrees.

4. Now you should have a compiled PHPUnit binary. Report any problems to us, if you cannot reach this far. To run the binary,

php phpunit.php (in PHP)  
/tmp/hphp_po33pK/program -f phpunit.php (in HipHop, note the -f flag)  
<pre name="code" class="cpp">php phpunit.php PHPUnit/Tests/Framework/SuiteTest.php  
/tmp/hphp_po33pK/program -v "Server.SourceRoot=`pwd`" \  
   -f phpunit.php PHPUnit/Tests/Framework/SuiteTest.php</pre>  
<pre></pre>  
<p></p>  
<pre></pre>  
<p></p>  
<p style="line-height:1.6; margin-top:15px; margin-bottom:15px; padding-top:0px; padding-bottom:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; font-size:14px; font:inherit">  
Note that the compiled binary “program” has to run from the same directory you normally run <code style="margin-top:0px; margin-right:2px; margin-bottom:0px; margin-left:2px; padding-top:0px; padding-right:5px; padding-bottom:0px; padding-left:5px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-style:initial; border-color:initial; font-size:12px; font:normal normal normal 12px/normal 'Bitstream Vera Sans Mono',Courier,monospace; white-space:nowrap; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(234,234,234); border-right-color:rgb(234,234,234); border-bottom-color:rgb(234,234,234); border-left-color:rgb(234,234,234); background-color:rgb(248,248,248)">phpunit.php</code>,  
 only because PHPUnit has<code style="margin-top:0px; margin-right:2px; margin-bottom:0px; margin-left:2px; padding-top:0px; padding-right:5px; padding-bottom:0px; padding-left:5px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-style:initial; border-color:initial; font-size:12px; font:normal normal normal 12px/normal 'Bitstream Vera Sans Mono',Courier,monospace; white-space:nowrap; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(234,234,234); border-right-color:rgb(234,234,234); border-bottom-color:rgb(234,234,234); border-left-color:rgb(234,234,234); background-color:rgb(248,248,248)">file_exists()</code> testing  
 that goes to local disk to look for some .php files. There is a way to remove this disk location dependency by building a static file cache, but we will leave that to some more advanced instructions.</p>  
<p style="line-height:1.6; margin-top:15px; margin-bottom:15px; padding-top:0px; padding-bottom:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; font-size:14px; font:inherit">  
Also note that <code style="margin-top:0px; margin-right:2px; margin-bottom:0px; margin-left:2px; padding-top:0px; padding-right:5px; padding-bottom:0px; padding-left:5px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-style:initial; border-color:initial; font-size:12px; font:normal normal normal 12px/normal 'Bitstream Vera Sans Mono',Courier,monospace; white-space:nowrap; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(234,234,234); border-right-color:rgb(234,234,234); border-bottom-color:rgb(234,234,234); border-left-color:rgb(234,234,234); background-color:rgb(248,248,248)">-v  
 "Server.SourceRoot=`pwd`"</code> normally is not needed. But PHPUnit has quite a few file location based operations that will try to compare source file name with what’s on local disk with <code style="margin-top:0px; margin-right:2px; margin-bottom:0px; margin-left:2px; padding-top:0px; padding-right:5px; padding-bottom:0px; padding-left:5px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-style:initial; border-color:initial; font-size:12px; font:normal normal normal 12px/normal 'Bitstream Vera Sans Mono',Courier,monospace; white-space:nowrap; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(234,234,234); border-right-color:rgb(234,234,234); border-bottom-color:rgb(234,234,234); border-left-color:rgb(234,234,234); background-color:rgb(248,248,248)">realpath()</code> calls.  
 So we had to add this one to run through the tests.</p>  
<p style="line-height:1.6; margin-top:15px; margin-bottom:15px; padding-top:0px; padding-bottom:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; font-size:14px; font:inherit">  
<strong>5. </strong>Some useful tips:</p>  
<p style="line-height:1.6; margin-top:15px; margin-bottom:15px; padding-top:0px; padding-bottom:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; font-size:14px; font:inherit">  
(1) If you just created a binary with <code style="margin-top:0px; margin-right:2px; margin-bottom:0px; margin-left:2px; padding-top:0px; padding-right:5px; padding-bottom:0px; padding-left:5px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-style:initial; border-color:initial; font-size:12px; font:normal normal normal 12px/normal 'Bitstream Vera Sans Mono',Courier,monospace; white-space:nowrap; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(234,234,234); border-right-color:rgb(234,234,234); border-bottom-color:rgb(234,234,234); border-left-color:rgb(234,234,234); background-color:rgb(248,248,248)">--keep-tempdir=1</code>,  
 but forgot to copy the name, a simple command can normally find it,</p>  
<pre style="margin-top:15px; margin-bottom:15px; padding-top:6px; padding-right:10px; padding-bottom:6px; padding-left:10px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-style:initial; border-color:initial; font-size:13px; font:normal normal normal 12px/normal 'Bitstream Vera Sans Mono',Courier,monospace; background-color:rgb(248,248,248); border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(204,204,204); border-right-color:rgb(204,204,204); border-bottom-color:rgb(204,204,204); border-left-color:rgb(204,204,204); line-height:19px; overflow-x:auto; overflow-y:auto"><code style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-style:initial; border-color:initial; font-size:12px; font:normal normal normal 12px/normal 'Bitstream Vera Sans Mono',Courier,monospace; border-top-style:none; border-right-style:none; border-bottom-style:none; border-left-style:none; background-color:transparent; border-width:initial; border-color:initial; border-width:initial; border-color:initial">ls -altrd /tmp/hphp_* | tail -1</code></pre>  
<p style="line-height:1.6; margin-top:15px; margin-bottom:15px; padding-top:0px; padding-bottom:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; font-size:14px; font:inherit">  
(2) You may run out of disk space with too many temporary directories. Just rm all HipHop temps like this,</p>  
<pre style="margin-top:15px; margin-bottom:15px; padding-top:6px; padding-right:10px; padding-bottom:6px; padding-left:10px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-style:initial; border-color:initial; font-size:13px; font:normal normal normal 12px/normal 'Bitstream Vera Sans Mono',Courier,monospace; background-color:rgb(248,248,248); border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(204,204,204); border-right-color:rgb(204,204,204); border-bottom-color:rgb(204,204,204); border-left-color:rgb(204,204,204); line-height:19px; overflow-x:auto; overflow-y:auto"><code style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-style:initial; border-color:initial; font-size:12px; font:normal normal normal 12px/normal 'Bitstream Vera Sans Mono',Courier,monospace; border-top-style:none; border-right-style:none; border-bottom-style:none; border-left-style:none; background-color:transparent; border-width:initial; border-color:initial; border-width:initial; border-color:initial">rm -fR /tmp/hphp_*</code></pre>  
<h2><a name="t10"></a>5 . Example: Running PHPUnit under HPHPi</h2>  
<div><pre name="code" class="csharp">$HPHP_HOME/src/hphpi/hphpi -f phpunit.php  
$HPHP_HOME/src/hphpi/hphpi -f phpunit.php PHPUnit/Tests/Framework/SuiteTest.php</pre></div>  
<p style="line-height:1.6; margin-top:15px; margin-bottom:15px; padding-top:0px; padding-bottom:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; font-size:14px; font:inherit">  
<span style="color:red">Haiping: We can pass all in SuiteTest.php, but we do have several other tests under PHPUnit/Tests/Framework that we’re not able to fully pass yet, due to some local disk assumption in PHPUnit and perhaps some minor bugs. Still debugging  
 to see if we can fix all these issues.</span></p>  
<h2><a name="t11"></a>6 . Example: Compiling WordPress</h2>  
<p style="line-height:1.6; margin-top:0px; margin-bottom:15px; padding-top:0px; padding-bottom:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; font-size:14px; font:inherit">  
<strong>1.</strong> Get a copy of WordPress. Please note, we identified 2 or 3 problems with WordPress that need to be fixed before HipHop can compile it. These have been fixed in trunk of the Wordpress <span class="caps" style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; font-size:14px; font:inherit">SVN</span> but  
 not backported.</p>  
<p style="line-height:1.6; margin-top:0px; margin-bottom:15px; padding-top:0px; padding-bottom:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; font-size:14px; font:inherit">  
</p>  
<pre name="code" class="cpp">wget http://wordpress.org/latest.tar.gz  
tar zxvf wordpress-2.9.1.tar.gz  
cd wordpress  
[patch language=" language=" to fix some PHP coding problems that will cause compilation errors""][/patch]</pre>  
<p></p>  
<p style="line-height:1.6; margin-top:15px; margin-bottom:15px; padding-top:0px; padding-bottom:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; font-size:14px; font:inherit">  
<strong>2.</strong> Create a config.php, perhaps by copying config.sample.php and set up database information. This file needs to be prepared <span class="caps" style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; font-size:14px; font:inherit">BEFORE</span> the  
 compilation, so it’s compiled into the final binary. Any changes of this file need a re-compilation of the whole package. <span class="caps" style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; font-size:14px; font:inherit">NOTE</span>:  
 use the loopback interface (typically ‘127.0.0.1’) instead of ‘localhost’; see <a href="http://groups.google.com/group/hiphop-php-dev/msg/4ca5cef95367be03?" style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; font-size:14px; font:inherit; color:rgb(65,131,196); text-decoration:none">this  
 thread</a> on the mailing list for an explanation.</p>  
<p style="line-height:1.6; margin-top:15px; margin-bottom:15px; padding-top:0px; padding-bottom:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; font-size:14px; font:inherit">  
<strong>3.</strong> This prepares a list of all <span class="caps" style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; font-size:14px; font:inherit">PHP</span> files  
 we want to compile:</p>  
<pre style="margin-top:15px; margin-bottom:15px; padding-top:6px; padding-right:10px; padding-bottom:6px; padding-left:10px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-style:initial; border-color:initial; font-size:13px; font:normal normal normal 12px/normal 'Bitstream Vera Sans Mono',Courier,monospace; background-color:rgb(248,248,248); border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(204,204,204); border-right-color:rgb(204,204,204); border-bottom-color:rgb(204,204,204); border-left-color:rgb(204,204,204); line-height:19px; overflow-x:auto; overflow-y:auto"><code style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-style:initial; border-color:initial; font-size:12px; font:normal normal normal 12px/normal 'Bitstream Vera Sans Mono',Courier,monospace; border-top-style:none; border-right-style:none; border-bottom-style:none; border-left-style:none; background-color:transparent; border-width:initial; border-color:initial; border-width:initial; border-color:initial">find . -name "*.php" > files.list</code></pre>  
<p style="line-height:1.6; margin-top:15px; margin-bottom:15px; padding-top:0px; padding-bottom:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; font-size:14px; font:inherit">  
<strong>4. </strong>Now we’re ready to compile the project.</p>  
<p style="line-height:1.6; margin-top:15px; margin-bottom:15px; padding-top:0px; padding-bottom:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; font-size:14px; font:inherit">  
</p>  
<pre name="code" class="cpp">$HPHP_HOME/src/hphp/hphp --input-list=files.list -k 1 --log=3 \  
  --force=1 --cluster-count=50</pre>  
<p></p>  
<p style="line-height:1.6; margin-top:15px; margin-bottom:15px; padding-top:0px; padding-bottom:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; font-size:14px; font:inherit">  
This is simpler than PHPUnit, because WordPress doesn’t have as much dynamic coding as PHPUnit does.</p>  
<p style="line-height:1.6; margin-top:15px; margin-bottom:15px; padding-top:0px; padding-bottom:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; font-size:14px; font:inherit">  
<strong>5.</strong> Now you should have a compiled binary. To run it,</p>  
<p style="line-height:1.6; margin-top:15px; margin-bottom:15px; padding-top:0px; padding-bottom:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; font-size:14px; font:inherit">  
</p>  
<pre name="code" class="cpp">sudo /tmp/hphp_xpl7hT/program -m server -v "Server.SourceRoot=`pwd`" \  
  -v "Server.DefaultDocument=index.php" -c $HPHP_HOME/bin/mime.hdf</pre>  
<p></p>  
<p style="line-height:1.6; margin-top:15px; margin-bottom:15px; padding-top:0px; padding-bottom:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; font-size:14px; font:inherit">  
<code style="margin-top:0px; margin-right:2px; margin-bottom:0px; margin-left:2px; padding-top:0px; padding-right:5px; padding-bottom:0px; padding-left:5px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-style:initial; border-color:initial; font-size:12px; font:normal normal normal 12px/normal 'Bitstream Vera Sans Mono',Courier,monospace; white-space:nowrap; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(234,234,234); border-right-color:rgb(234,234,234); border-bottom-color:rgb(234,234,234); border-left-color:rgb(234,234,234); background-color:rgb(248,248,248)">sudo</code> because  
 we need to listen to port 80, the only port WordPress works on.</p>  
<p style="line-height:1.6; margin-top:15px; margin-bottom:15px; padding-top:0px; padding-bottom:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; font-size:14px; font:inherit">  
<code style="margin-top:0px; margin-right:2px; margin-bottom:0px; margin-left:2px; padding-top:0px; padding-right:5px; padding-bottom:0px; padding-left:5px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-style:initial; border-color:initial; font-size:12px; font:normal normal normal 12px/normal 'Bitstream Vera Sans Mono',Courier,monospace; white-space:nowrap; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(234,234,234); border-right-color:rgb(234,234,234); border-bottom-color:rgb(234,234,234); border-left-color:rgb(234,234,234); background-color:rgb(248,248,248)">-m  
 server</code> runs the program in server mode. <code style="margin-top:0px; margin-right:2px; margin-bottom:0px; margin-left:2px; padding-top:0px; padding-right:5px; padding-bottom:0px; padding-left:5px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-style:initial; border-color:initial; font-size:12px; font:normal normal normal 12px/normal 'Bitstream Vera Sans Mono',Courier,monospace; white-space:nowrap; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(234,234,234); border-right-color:rgb(234,234,234); border-bottom-color:rgb(234,234,234); border-left-color:rgb(234,234,234); background-color:rgb(248,248,248)">-m  
 daemon</code> is okay as well.</p>  
<p style="line-height:1.6; margin-top:15px; margin-bottom:15px; padding-top:0px; padding-bottom:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; font-size:14px; font:inherit">  
<code style="margin-top:0px; margin-right:2px; margin-bottom:0px; margin-left:2px; padding-top:0px; padding-right:5px; padding-bottom:0px; padding-left:5px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-style:initial; border-color:initial; font-size:12px; font:normal normal normal 12px/normal 'Bitstream Vera Sans Mono',Courier,monospace; white-space:nowrap; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(234,234,234); border-right-color:rgb(234,234,234); border-bottom-color:rgb(234,234,234); border-left-color:rgb(234,234,234); background-color:rgb(248,248,248)">-v  
 "Server.SourceRoot=`pwd`"</code> We still need this to locate image and css files.</p>  
<p style="line-height:1.6; margin-top:15px; margin-bottom:15px; padding-top:0px; padding-bottom:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; font-size:14px; font:inherit">  
<code style="margin-top:0px; margin-right:2px; margin-bottom:0px; margin-left:2px; padding-top:0px; padding-right:5px; padding-bottom:0px; padding-left:5px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-style:initial; border-color:initial; font-size:12px; font:normal normal normal 12px/normal 'Bitstream Vera Sans Mono',Courier,monospace; white-space:nowrap; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(234,234,234); border-right-color:rgb(234,234,234); border-bottom-color:rgb(234,234,234); border-left-color:rgb(234,234,234); background-color:rgb(248,248,248)">-v  
 "Server.DefaultDocument=index.php"</code>, so http://server/ would work.</p>  
<p style="line-height:1.6; margin-top:15px; margin-bottom:15px; padding-top:0px; padding-bottom:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; font-size:14px; font:inherit">  
<code style="margin-top:0px; margin-right:2px; margin-bottom:0px; margin-left:2px; padding-top:0px; padding-right:5px; padding-bottom:0px; padding-left:5px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-style:initial; border-color:initial; font-size:12px; font:normal normal normal 12px/normal 'Bitstream Vera Sans Mono',Courier,monospace; white-space:nowrap; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(234,234,234); border-right-color:rgb(234,234,234); border-bottom-color:rgb(234,234,234); border-left-color:rgb(234,234,234); background-color:rgb(248,248,248)">-c  
 $HPHP_HOME/bin/mime.hdf</code> has a list of static content file extensions that need to be loaded by the server to be able to serve those files with different <span class="caps" style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; font-size:14px; font:inherit">MIME</span> headers.</p>  
<p style="line-height:1.6; margin-top:15px; margin-bottom:15px; padding-top:0px; padding-bottom:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; font-size:14px; font:inherit">  
If you want to see verbose logging, add these flags,</p>  
<p style="line-height:1.6; margin-top:15px; margin-bottom:15px; padding-top:0px; padding-bottom:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; font-size:14px; font:inherit">  
<code style="margin-top:0px; margin-right:2px; margin-bottom:0px; margin-left:2px; padding-top:0px; padding-right:5px; padding-bottom:0px; padding-left:5px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-style:initial; border-color:initial; font-size:12px; font:normal normal normal 12px/normal 'Bitstream Vera Sans Mono',Courier,monospace; white-space:nowrap; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(234,234,234); border-right-color:rgb(234,234,234); border-bottom-color:rgb(234,234,234); border-left-color:rgb(234,234,234); background-color:rgb(248,248,248)">-v  
 "Log.Level=Verbose"</code> This will output a lot more errors, warnings and information.<br>  
<code style="margin-top:0px; margin-right:2px; margin-bottom:0px; margin-left:2px; padding-top:0px; padding-right:5px; padding-bottom:0px; padding-left:5px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-style:initial; border-color:initial; font-size:12px; font:normal normal normal 12px/normal 'Bitstream Vera Sans Mono',Courier,monospace; white-space:nowrap; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(234,234,234); border-right-color:rgb(234,234,234); border-bottom-color:rgb(234,234,234); border-left-color:rgb(234,234,234); background-color:rgb(248,248,248)">-v  
 "Log.NoSilencer=on"</code> This prints out errors from statements that have “@” operators, which WordPress code uses a lot.<br>  
<code style="margin-top:0px; margin-right:2px; margin-bottom:0px; margin-left:2px; padding-top:0px; padding-right:5px; padding-bottom:0px; padding-left:5px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-style:initial; border-color:initial; font-size:12px; font:normal normal normal 12px/normal 'Bitstream Vera Sans Mono',Courier,monospace; white-space:nowrap; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(234,234,234); border-right-color:rgb(234,234,234); border-bottom-color:rgb(234,234,234); border-left-color:rgb(234,234,234); background-color:rgb(248,248,248)">-v  
 "Log.Header=on"</code> This will print a header for each line of logging. The most interesting in the header is a long string with hex-encoding. That’s hex-encoded stacktrace. To translate it into something readable, run this command,</p>  
<pre style="margin-top:15px; margin-bottom:0px!important; padding-top:6px; padding-right:10px; padding-bottom:6px; padding-left:10px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-style:initial; border-color:initial; font-size:13px; font:normal normal normal 12px/normal 'Bitstream Vera Sans Mono',Courier,monospace; background-color:rgb(248,248,248); border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(204,204,204); border-right-color:rgb(204,204,204); border-bottom-color:rgb(204,204,204); border-left-color:rgb(204,204,204); line-height:19px; overflow-x:auto; overflow-y:auto"><code style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-style:initial; border-color:initial; font-size:12px; font:normal normal normal 12px/normal 'Bitstream Vera Sans Mono',Courier,monospace; border-top-style:none; border-right-style:none; border-bottom-style:none; border-left-style:none; background-color:transparent; border-width:initial; border-color:initial; border-width:initial; border-color:initial">/tmp/hphp_xpl7hT/program -m translate the-long-hex-string-without-brackets  
</code></pre>  
<pre></pre>  
<pre></pre>  
<pre></pre>  
<pre></pre>  
<pre></pre>  
<pre></pre>  
<pre></pre>  
<pre></pre>  
<pre></pre>  
<pre></pre>  
<pre></pre>  
<pre></pre>  
Last edited by pierregoudjo, 3 months ago

官方安装文档:https://github.com/facebook/hiphop-php/wiki/Building-and-Installing-on-Ubuntu-11.10

稍微做一些修改而已.

Building and Installing on Ubuntu 11.10

1、Packages installation (安装依赖的包):

  • cmake 2.6 is the minimum version

  • g++/gcc 4.3 is the minimum version

  • Boost 1.37 is the minimum version

  • flex

  • bison

  • re2c

  • libmysql

  • libxml2

  • libmcrypt

  • libicu 4.2 is the minimum version

  • openssl

  • binutils

  • libcap

  • gd

  • zlib

  • tbb Intel's Thread Building Blocks

  • Oniguruma

  • libpcre

  • libexpat

  • libmemcached

The following packages have had slight modifications added to them. Patches are provided and should be made against the current source copies.

  • libcurl

  • src/third_party/libcurl.fb-changes.diff

  • libevent 1.4

  • src/third_party/libevent-1.4.13.fb-changes.diff OR src/third_party/libevent-1.4.14.fb-changes.diff

Using sudo or as root user:

As outlined in the 11.04 instructions plus the addition of the required libcloog-ppl0 package for 11.10

sudo apt-get install git-core cmake g++ libboost-dev libmysqlclient-dev libxml2-dev libmcrypt-dev libicu-dev openssl build-essential 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 libbz2-dev libc-client2007e-dev php5-mcrypt php5-imagick libgoogle-perftools-dev libcloog-ppl0

2、Getting HipHop source-code(获取HipHop源码包

mkdir dev    
cd dev    
git clone git://github.com/facebook/hiphop-php.git    
cd hiphop-php    
export CMAKE_PREFIX_PATH=`pwd`    
export HPHP_HOME=`pwd`    
export HPHP_LIB=`pwd`/bin    
cd ..

3. Building third-party libraries 安装第三方库

1) libevent

wget http://www.monkey.org/~provos/libevent-1.4.14b-stable.tar.gz    
tar -xzvf libevent-1.4.14b-stable.tar.gz    
cd libevent-1.4.14b-stable    
cp ../hiphop-php/src/third_party/libevent-1.4.14.fb-changes.diff .    
patch -p1 < libevent-1.4.14.fb-changes.diff    
./configure --prefix=$CMAKE_PREFIX_PATH    
make    
make install    
cd ..

 2) libCurl 安装libcurl

Make sure that your system time is correct, otherwise ./configure will fail.(确保系统时间正确,否则 ./configure 会出错.

wget http://curl.haxx.se/download/curl-7.21.2.tar.gz    
tar -xvzf curl-7.21.2.tar.gz    
cd curl-7.21.2    
cp ../hiphop-php/src/third_party/libcurl.fb-changes.diff .    
patch -p1 < libcurl.fb-changes.diff    
./configure --prefix=$CMAKE_PREFIX_PATH

As per: https://github.com/bagder/curl/commit/26b487a5d6ed9da5bc8e4a134a88d3125884b852

  • Edit lib/ssluse.c

As per: https://github.com/facebook/hiphop-php/issues/319#issuecomment-1445537

  • Edit runtime/ext/extension.cpp

make    

make install    

cd ..  

 

3 )libmemcached (安装libmemcached库)

  1. wget http://launchpad.net/libmemcached/1.0/0.49/+download/libmemcached-0.49.tar.gz    

  2. tar -xzvf libmemcached-0.49.tar.gz    

  3. cd libmemcached-0.49    

  4. ./configure –prefix=$CMAKE_PREFIX_PATH    

  5. make    
    make install    
    cd ..

4. Building HipHop(安装Hiphop)

cd hiphop-php    
git submodule init    
git submodule update    
cmake .    
make

hphp binary can be found in src/hphp folder and is called hphp

If any errors occur, it may be required to remove the CMakeCache.txt directory in the checkout.

If your failure was on the make command, try to correct the error and run make again, it should restart from the point it stops. If don’t, try to remove as explained above.

转自:http://blog.csdn.net/hguisu/article/details/7403855

原创文章,作者:s19930811,如若转载,请注明出处:http://www.178linux.com/3038

(0)
上一篇 2015-04-10 21:19
下一篇 2015-04-10 21:19

相关推荐

  • Linux终端类型

    Linux终端类型 Linux的终端类型包括控制台终端、虚拟终端、伪终端、串行终端、控制终端、图形终端。   终端 要理解伪终端(Pseudo Terminal),先来看看什么是“终端”(Terminal)。 终端是一种字符型设备,它有多种类型,通常使用tty来简称各种类型的终端设备。 1、串行端口终端(/dev/ttySx) 串行端口终端(Ser…

    Linux干货 2016-10-14
  • 马哥教育网络班22期+第6周课程练习 忍者乱太郎喻成

    请详细总结vim编辑器的使用并完成以下练习题 1、复制/etc/rc.d/rc.sysinit文件至/tmp目录,将/tmp/rc.sysinit文件中的以至少一个空白字符开头的行的行首加#cp /etc/rc.d/rc.sysinit /tmp方法一 vim法在vim下用 : 进入命令行模式     %s/^&nbs…

    Linux干货 2016-10-24
  • 单向加密原理

      单向加密算法对数据进行加密的过程分为两个步骤:   一、添加特征码           上图中说明了为数据添加特征码的步骤:       1、使用单向算法计算出特征码       2、使用私钥来加密特征码   &nb…

    Linux干货 2016-02-24
  • linux做路由并实现路由转发

    一、环境介绍 1.linux版本:CentOS6.8,CentOS7.2两台主机分别加载两块网卡,分别作为路由器的两个端口 2.实验在vmware虚拟机中完成 3.另有两台CentOS6.8和CentOS7.2作为两个网段的主机 4.实验图示: 二、路由1(左)和路由2(右)的设置 1.路由1配置信息 eth0网卡:    &n…

    Linux干货 2016-09-07
  • class14磁盘管理(一)

    一、硬盘基础知识及分区类型 1、磁盘结构 设备文件 I/O Ports: I/O 设备地址 一切皆文件:   open(), read(), write(), close() 设备类型: 块设备:block,存取单位“块”,磁盘 字符设备:char,存取单位“字符”,键…

    Linux干货 2016-08-29
  • 马哥教育网络班第21期+第三周课程作业

    1. 列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可。 who | awk  '{print $1}'|uniq 2.列出最后登录到当前系统的用户的相关信息 last | head -1   3. 读取当前系统上被用户当做其默认shell最多的那个shell cat /etc/pa…

    Linux干货 2016-07-26