Use ZendEncode to compile and develop the PHP program _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Tags php compiler
Use ZendEncode to write and develop PHP programs. Anyone who uses PHP knows that ZendEncode is a script programming tool. programs written with it must be placed on the Web server in the form of source code, so anyone who can't protect their source code using PHP knows that Zend Encode is a script programming tool. programs written with it must be placed on the Web server in the form of source code, therefore, we cannot protect our 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. 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)

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

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.