Use Zend encode to write and develop PHP programs

Source: Internet
Author: User
Tags php compiler


Anyone who uses PHP knows that Zend encode is a script programming tool that uses it to write Program , Must be placed on the web server in the form of source code, so we cannot protect our own Source code . Everyone knows that the execution efficiency of any script program is the same as that of compiled binary programs with the same function. Code In comparison, the execution efficiency is relatively low. If there is a tool that can help us compile the program written in PHP into binary code, this will not only improve the execution efficiency, but also speed up the operation. If there is such a tool, it would be two birds in one fell swoop.
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 the http://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
<? Phpinfo ();?>
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 http: // 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]
<?
$ T = time ();
For ($ I = 0; I I <1000000; $ I ++ ){
If ($ I % 20 )! = 0) {echo $ I; echo ",";}
Else {echo "<br> ";}
}
$ T1 = Time ();
Echo "<br>"; echo "It used:"; echo $ T1-$ t; 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. (Source: Wind flash network road College)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.