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

How to convert php code to c code

藏色散人
藏色散人Original
2020-07-22 09:00:513135browse

How to convert php code to c code: first, you need to rely on the package and patch it based on the source code; then specify the location of CMake; then compile; finally use hphp to directly compile into c code and execute it That’s it.

How to convert php code to c code

Compile PHP code into C/C code to make your PHP run faster

Recommendation: "PHP Tutorial"

FaceBook has released a tool that can convert PHP code into C, hiphop

If your website is large, such as Sina Portal can be considered.

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

Installation:

1. Dependent packages

cmake2.6 is the minimum version
g++/gcc4.3 is the minimum version
Boost1.37 is the minimum version
flex
bison
re2c
libmysql
libxml2
libmcrypt
libicu4.2 is the minimum version
openssl
binutils
libcap
gd
zlib
tbbIntel'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 CMake Position

export CMAKE_PREFIX_PATH=/home/user

3. Compilation

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 rarely used method of eval cannot be included in the PHP code.

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 这个根据你自己生成的运行

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 code. 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