Anyone who uses PHP knows that it is a script programming tool. programs written with it must be placed on the Web server in the form of source code, so we cannot protect our own source code. How Zend Encode works
Anyone who uses PHP knows that it is a script programming tool. programs written with it must be placed on the Web server in the form of source code, so we cannot protect our own source code. We all know that the execution efficiency of any script program is lower than that of compiled binary code with the same function. So if there is a tool that can help us compile programs written in PHP
Just translate the code into binary code, which not only improves the execution efficiency,
The operation speed is also accelerated. If there is such a tool, it is
It takes two minutes.
This is not a dream. Zend Encode is developed for this purpose. it can directly compile the script into a binary code. With Zend Encode, you can compile your PHP program and distribute it to many users without disclosing your source code. The compiled binary code can be transparently read by Zend Optimizer. that is to say, you only need to install Zend Optimizer on its server to execute the PHP program compiled by Zend Encode. The compilation program contains some Zend Optimizer code, so the program code is further optimized during the compilation process, which means the script execution efficiency is improved.
In a sense, Zend Encode is a "PHP compiler ". However, it is not a true compiler, because the truly compiled program can run out of the original compilation environment, and the Zend Encode compiled program, zend Optimizer is required. Just like compiled Java binary code, it must be supported by JVM. Therefore, Zend Optimizer can be viewed as a virtual machine with PHP compiled code. In any case, they must be used together.
Currently, Zend Encode supports the following operating systems: Solaris, Linux, FreeBSD, and Windows. Zend Encode can be run directly, and PHP does not have to be installed in computer systems.
Zend Encode installation
Download a software package first! Zend Encode is not a free software. you have to pay for it and the price is quite high. Fortunately, zend.com provides a software package for trial. you can try it for 30 days for free. This package can be obtained directly from www.zend.com. Therefore, you must first download the Zend Encode and Zend Optimizer packages on www.zend.com. Download an authorization file license. Because Zend Encode is an authorized product, you need to apply for a license from zend.com.
The application procedure is as follows:
To apply for a license for trial use, you must provide the ID of the computer you are using to zend.com, that is, enter the host ID in the application page (actually the MAC address of the NIC on your computer ). The method for viewing the computer ID is as follows: download an lmutil. z program from zend.com, decompress it, obtain the program lmutil, and run it. it will generate a sequence string based on the hardware features of the system. Enter the serial number in the host ID on the apply for license page. zend.com will generate a license for the user within 48 hours and download the license file named zendEncode. dat, which can only be used on this computer.
1. decompress the Zend Encode package to the/usr/local/Zend directory. After decompression, a zendenc file is added to the directory, which is the "Compiler.
2. copy the license file to the/usr/local/Zend directory for installation.
Zend Optimizer installation
After Zend Encode is installed, half of the tasks are completed. to use the compiled PHP binary code, you must also install the interpreter Zend Optimizer. with its support, the compiled PHP binary file can be correctly executed.
Unlike Zend Encode, Zend Optimizer is a free software. its main function is to accelerate the running of PHP script files. According to Zend.com, with Zend Optimizer optimization, the execution efficiency of the program can be improved by 600%. after the author's simple test, the execution efficiency is indeed improved a lot.
To install Zend Optimizer, follow these steps:
1. decompress the Zend Optimizer package and copy the zendoptimizer. so file to the/usr/local/Zend/lib directory.
2. open the/usr/local/lib/PHP. ini file and add the following two lines to the file:
Zend_optimizer.optimization_level = 15
Zend_extension = "/usr/local/Zend/lib/zendoptimizer. so"
3. restart the Apache server to make the above updates take effect.
Use of Zend Encode
Now all the preparation is complete. let's write a simple PHP script and compile it with Zend Encode to see how it works. First, write a simple script to see if the compiled code can be executed:
# Vi test. PHP
Compile it:
# [Root @ mail Zend] #./zendenc test. PHP testencode. PHP
Zend Encoder Unlimited (test drive) v1.1.0 (c) Zend Technologies 1999-2000
Licensed to: xqkred.
Compiling test. PHP...
Done encoding test. PHP.
Optimizing... Done.
Saving... Done.
Yes, compilation is successful. However, the size of compiled programs is much larger than before.
Copy testencode. PHP to the release directory of the Web server, and type localhost/testencode. PHP in the browser. wow! The compiled code can be successfully run! Because we use Zend Encode as a trial version, an image will appear at the top of the page, indicating that this is a binary file generated by the Zend Encode trial package. In the official version of the software, images will not be reproduced.
Let's take a look at its execution efficiency! First, write a small computing program to make a rough estimate:
[Compute. PHP]
The code is as follows:
R = time ();
For (121 = 0; 121 <1000000; 121 ++ ){
If (121% 20 )! = 0) {echo 121; echo ",";}
Else {echo"
";}
}
= Time ();
Echo"
"; Echo" It used: "; echo-r; echo" seconds ";
?>
When this program is executed, it takes the system time, and then the system time after the program is completed. The difference between the two values is the time required for the entire program to run. it is first executed without compilation, then use Zend Encode to compile and execute it again. Comparison results: In the absence of compilation, the average running time is 19 seconds, and the average execution time of compiled code is 9 seconds. it seems that the execution efficiency has improved a lot.