Use ZendEncode to compile PHP project_php tutorial-PHP Tutorial

Source: Internet
Author: User
Tags php compiler
Use ZendEncode to compile the PHP program. 1. anyone who uses PHP knows how ZendEncode works. it is a script programming tool. programs written by it must be placed on Web servers in the form of source code, therefore, we cannot guarantee the working principle of ZendEncode.

Anyone who uses PHP knows that it is a script programming tool. programs written by it must be placed on the Web server in the form of source code, so we cannot protect our source code. As you all know, the execution efficiency of any script program is slower 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.

The ZendEncode just released was developed for this purpose. ZendEncode can directly compile the script into a binary code. With ZendEncode, 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 ZendEncode. 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, ZendEncode is a "PHP compiler ". However, it is not a true compiler. in the true sense, the compiler runs out of the original compiling environment, and ZendEncode compiled programs must support ZendOptimizer, just like compiled java binary code, it must have a JVM to run. Therefore, ZendOptimizer can be viewed as a virtual machine with php compiled code. In any case, they must be used together.

Currently, ZendEncode supports the following operating systems: Solaris, Linux, FreeBSD, and Windows. ZendEncode can be run directly. you do not have to install php in your system.


II. ZendEncode installation (this article takes installation in linux as an example)

Download a software package first! ZendEncode 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 directly renewed from http://www.zend.com. Therefore, you must first download the zendencode=zendoptimizersoftware package at http://www.zend.com. Next, you need to download an authorization file, that is, license. Because ZendEncode is an authorized product, you need to apply for a license from zend.com. To apply for a card, follow these steps:

To apply for a license for trial use, you must provide the id of the computer you are using to zend.com, that is, the host ID to be filled 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 from zend.com. z program, decompress it, obtain the program lmutil, run it, and generate a serial string according to the hardware features of the system. Enter the serial numbers in the hostid on the license application page. zend.com will generate a license for the user within 48 hours and download the license file named zendEncode. dat, which is the only one that can be used on your computer.

1. decompress the ZendEncode package in 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.

Installation is complete.

III. installation of ZendOptimizer

After ZendEncode is installed, half of the tasks are completed. to use the compiled php binary code, you must install the interpreter ZendOptimizer. with its support, the compiled php binary file can be correctly executed.

Unlike ZendEncode, ZendOptimizer is a free software. its main function is to accelerate the running of php script files. according to Zend.com, with ZendOptimizer optimization, the program execution efficiency can be improved by 600%, after the author's simple test, the execution efficiency has indeed improved a lot.

To install ZendOptimizer, follow these steps:

1. decompress the zendOptimizer 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.


IV. Use of ZendEncode

All right, all the above preparations have been completed. now, write a simple php script and compile it with zendEncode to see how it works. well, write the simplest script first, check whether 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©Zend Technologies, September 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 run successfully! Because we use ZendEncode as a trial version, an image is displayed at the top of the page, indicating that this is a binary file generated by the ZendEncode trial package. As shown in:


If you have purchased the official version, the figure above 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 )! = 0) {echo $ I; echo ",";}

Else {echo"
";}

}

$ T1 = time ();

Echo"
"; 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 ZendEncode 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.

5. Note

Due to the fast development speed of php, its version number is also updated very quickly. if you follow the above practice, but your browser shows a mess of code, it means that, your php version does not match the ZendOptimizer version in use. you only need to download the corresponding ZendOptimizer again to solve the above garbled problem. In addition, pay attention to the version of the software package you downloaded. in linux, there are glibc and libc. Glibc software packages should be downloaded in versions later than Redhat 6.

Everyone who uses PHP in ghost knows that it is a script programming tool. programs written by ghost must be placed on the Web server in the form of source code, so we cannot protect it...

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.