Compile PHP programs with Zendencode
Author: Xue Qikang Time: 2004-04-11 23:37:03 from: http: //www.linuxforum.net Editor: clc
First, Zendencode works
People who use PHP know that it is a script programming tool, written by it, must be placed on the web server in the form of the source code, so we can't protect your source code. And everyone knows that the execution efficiency of any script is compared to the compiled binary code with the same function, it is slow. Then if you have a tool to help us compile the program written in the second-binary code with PHP, it is not only improved, but the speed is also accelerated. If you have such a tool, it is a two.
Just, the Zendencode just released is to be developed. Zendencode can directly compile scripts into binary code. With Zendencode, you can write your own PHP program and compile it to many users, but don't use your source code code. Compiled binary code can be read by Zend Optimizer, that is, the customer can perform PHP programs compiled by ZendEncode as long as the customer installs Zend Optimizer on his server. The compiler contains partial code of Zend Optimizer, so the program code is further optimized during the compilation process, which means that the execution efficiency of the script is improved.
In a certain sense, ZendEncode is a "PHP compiler". However, it is not a true compiler. The true compiler will be separated from the original compilation environment, and the ZendEncode compiled, and there must be Zendoptimizer support, just like compilation Java binary code. It has a JVM to run. Therefore, Zendoptimizer can also be seen as a virtual machine that is compiled by PHP. Anyway, this is such a thing, they have to use each other.
The operating system currently supported by Zendencode has: Solaris, Linux, FreeBSD and Windows. ZendEncode can run directly, do not necessarily have PHP in your system.
Second, the installation of zendencode (this article is installed as an example of the installation under the Linux environment)
Let's go to download a package! Zendencode is not free software, use it to pay, and the price is quite high. Fortunately, Zend.com provides a package for trial, and users can trial for 30 days. This package can be obtained directly from http://www.zend.com. So, first download the ZendEncode, Zendoptimizer package on www.zend.com. Second, download a license file, that is, License. Since ZendEncode is a product that is authorized, it is necessary to apply for a license from Zend.com. The application card steps are as follows:
To apply for a trial license, you need to provide the ID of the computer you are using to zend.com, which is the Host ID you want to fill in the application page (actually the MAC address on your computer), check the computer ID The method is as follows: Download a LMUTIL.Z program from Zend.com, get the program LMUTIL after decompression, run it, generate a sequence string according to the hardware feature of the system. In the hostid of the application license page, Zend.com generates a license within 48 hours, download this license file, the file name is Zendencode.dat, which is the only one can be used on your computer . 1. Unzip the Zendencode package in / usr / local / zend directory. After the decompression is completed, there is a more zendenc file in the directory, which is the "compiler".
2, copy the license file to / usr / local / zend directory
The installation is complete.
Third, the installation of Zendoptimizer
Completed the installation of ZendEncode, only half of the task, to use the compiled PHP binary code, but also install an interpreter -zeoptimizer, with its support, compiled PHP binary files can be executed correctly.
Unlike Zendencode, ZendOptimizer is a free software. Its main function is to speed up the PHP script file. According to Zend.com, there is a Zendoptimizer optimization, the execution efficiency of the program can increase 600%, and the author's simple test, execute Efficiency is indeed a lot.
Installing the ZendOptimizer steps as follows:
1, unzip the Zendoptimizer package, copy the ZendOptimizer.so file to / usr / local / zend / lib directory
2, open the /usr/local/lib/php.ini file, add the following two lines in the file:
Zend_Optimizer.optimization_level = 15
Zend_extension = "/ usr / local / zend / lib / zendoptimizer.so"
3, restart the Apache server to make the above update
Four, Zendencode's use
Ok, all the above preparations are all completed, and now write a simple PHP script. Use ZendEncode to look at the effect, good, write a simple script first, see if the compiled code can be executed:
#vi test.php
Compile it:
# [root @ Mail Zend] # ./zendenc test.php tester-name.php
Zend Encoder Unlimited (Test Drive) v1.1.0 (c) Zend Technologies, 1999-2000
Licensed to: xqkred.
Compiableing test.php ...
Done Encoding Test.php.
Optimizing ... DONE.
Saving ... done.
Ok, successfully compile. However, the size of the program is much larger than before.
Type TestenCode.php to the WEB server's publishes, type http: //localhost/testencode.php: //localhost/testen, on your browser, wow, compiled code can be successfully run! Since we use it is a trial version of Zendencode, so, A picture appears on the top of the page, which is a binary file generated by the ZendEncode trial package. As shown in the figure below: Purchase the official version of the user, the illustration above will not be reproduced.
Let's take a look at its execution efficiency! First write a small computing program rough estimate: compute.php
$ T = Time ();
For ($ I = 0; $ I <1000000; $ i ) {
IF (($ I% 20)! = 0) {ECHO $ I; Echo ",";
Else {ECHO "
"}
}
$ T1 = TIME ();
echo "
"Echo" IT used: "; Echo $ T1- $ T; Echo" Seconds ";
?>
When this program is executed, take the system time, after completing the system time, the difference between the two values is running for the entire program, first execute it without compiling, then use Zendencode to compile it to execute it again. . Compare each one another: If there is no compilation, the time required for operation is 19 seconds, and the average execution time after the compiled code is 9 seconds, and it seems that the performance efficiency has improved a lot.
Five, pay attention
Since the development speed of PHP is very fast, its version number is also newer, if you do it according to the above practices, but your browser shows a mess, then explain, your PHP and the Zendoptimizer version of your PHP is not Match, you can solve the above garbled problem as long as you re-download the corresponding ZendOptimizer. Also, pay attention to the version of the package you downloaded, in the Linux environment, there are Glibc and Libc points. The version after RedHat 6 should download the Glibc type package.