Home  >  Article  >  Backend Development  >  How to convert php code to c

How to convert php code to c

藏色散人
藏色散人Original
2020-10-09 10:21:102466browse

How to convert php code to c: first install the dependent packages; then specify the location of CMake; then compile through commands such as "export HPHP_HOME=`pwd`"; finally compile directly into c code and execute it That’s it.

How to convert php code to c

Recommended: "PHP Video Tutorial"

Compile PHP code into C/C code to make your php runs faster

FaceBook has released a tool that can convert php code to C, hiphop

If your website is large, such as a large portal like Sina, you can consider it.

It has been compiled and passed on Linux servers such as CentOS and ubuntu.

Installation:

1. Dependent packages

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 need to be patched based on the source code

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

2. Specify the location of CMake

export CMAKE_PREFIX_PATH=/home/user

3. Compile

cd /home/user/dev
git clone git://github.com/facebook/hiphop-php.git
cd hiphop-php
git submodule init
git submodule update
export HPHP_HOME=`pwd`
export HPHP_LIB=`pwd`/bin
make
cmake .

According to Facebook, the performance can be improved by about 50%, provided that The php code cannot contain the rarely used method eval.

4. Use hphp

Environment settings:

cd .. # 进入hphp的根目录,源码的存放目录
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`/../

There are several modes

1: Directly compile into c code and execute

hphp/hphp test.php

2: Compile to a temporary folder and execute the compiled c program

hphp/hphp test.php --keep-tempdir=1 --log=3

/tmp /hphp_p6vSsP/program This is run based on your own generated

3: Compile php as a service and run it on the specified port

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

The above is the detailed content of How to convert php code to c. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn