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.www58058.com/3038

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

相關推薦

  • 用戶和組命令的簡單使用

    用戶和組管理命令: 用戶管理命令:useradd usermod userdel 組管理命令:groupadd groupmod groupdel 用戶創建:useradd -u:uid 定義在/etc/login.defs -o:配合-u選項,不檢查uid的唯一性 -g:gid,指明用戶所屬基本組,可為組名,也可以gid -c:用戶的詮釋信息 -d;指定用…

    Linux干貨 2016-10-24
  • Mariadb數據庫備份恢復系列(二):xtrabackup物理備份工具之完全備份

    實驗二:利用xtrabackup+二進制日志實現完全備份和恢復數據庫 1、安裝xtrabackup軟件包 2、驗證數據的存儲引擎類型 3、查看數據初始狀態 4、利用innobackupex進行完全備份 5、進行apply-log操作 6、查看備份出來的文件的信息 7、模擬在完全備份后,對數進行修改,以測試通過二進制日志還原完全備份后尚未來得及備份的變化的數據…

    Linux干貨 2016-11-24
  • 文本處理工具(練習+作業)

    文本處理工具(cut,sort,uniq)練習 1、找出ifconfig命令結果中本機的所有IPv4地址 [root@localhost ~]# ifconfig | tr -cs '[:digit:].' '\n'| sort -t. -k3 |tail -5 2、查出分區空間使用率的最大百分比值 [root@loc…

    Linux干貨 2016-08-07
  • Bash的基礎特性(二)

    Bash的基礎特性(二) glob文件通配符 (* ; ? ; [ ] ; [^ ] ) 星號* 匹配任意所有字符的 [root@lyp ~]# ls h* hello.sh hello.shbak ?匹配單個字符 ls ???? 查看四個字符命名的文件 [0-9]匹配數字 [a-z] 字母 字母的順序安裝 a A b B c C… z Z 匹配的a-z […

    Linux干貨 2017-04-01
  • N25第二周博客作業

    第二周博客作業: 1、linux上的文件管理命令都有哪些,其常用的使用方法及其相關示例演示。                    有  cp  mv&nbsp…

    Linux干貨 2016-12-06
  • 搜索引擎-網絡爬蟲

     通用搜索引擎的處理對象是互聯網網頁,目前網頁數量以百億計,搜索引擎的網絡爬蟲能夠高效地將海量的網頁數據傳下載到本地,在本地 形成互聯網網頁的鏡像備份。它是搜索引擎系統中很關鍵也很基礎的構件。 1. 網絡爬蟲本質就是瀏覽器http請求。      瀏覽器和網絡爬蟲是兩種不同的網絡客戶端,都以相同的方式來獲取網…

    Linux干貨 2015-11-18
欧美性久久久久