Writing and developing PHP programs with Zend Encode

Source: Internet
Author: User
Tags copy download zend execution install php php compiler php script zend
The encode| program uses PHP to know that it is a scripting tool, the program written with it must be in the form of the source code on the Web server, so we can not protect their source. It is well known that the execution efficiency of any script program is lower than that of a compiled binary code with the same function. So if there's a tool that can help us compile the PHP program into binary code, then it's not only more efficient,
The speed of operation is also accelerated. If there was such a tool, it would be to kill the birds with one stone.

Now this is not a dream, Zend encode is developed for this, it can directly compile the script into binary code. With Zend Encode, you can write your own PHP program, compiled and distributed to a lot of users, rather than exposing their source code. Compiled binaries can be read transparently by Zend Optimizer, which means that customers can perform PHP programs compiled by Zend encode by installing Zend Optimizer on his server. The compiler contains part of the code for Zend Optimizer, so the program code is optimized further during compilation, which means that the execution efficiency of the script is improved.

In some sense, Zend encode is a "PHP compiler". However, it is not a true compiler, because the actual compiled program can be run away from the original compilation environment, and Zend encode compiled programs, need to have Zend Optimizer support. Just like compiling a good Java binary code, you need the support of the JVM. So, Zend Optimizer can be seen as a virtual machine that PHP compiles good code. In any case, they are used in conjunction with each other.

The operating systems currently supported by Zend Encode are: Solaris, Linux, FreeBSD, and Windows. Zend encode can be run directly, the computer system does not necessarily have to install PHP.

Installation of Zend encode

Download a package first! Zend encode is not free software, it pays to use it, and the price is quite high. Luckily Zend.com offers a software package that can be tested for a free trial for 30 days. This package can be obtained directly from the www.zend.com. So, first of all, go to www.zend.com download Zend Encode, Zend Optimizer package. Second, to download an authorization file license. Because Zend Encode is a licensed product, users are required to apply for a license from the zend.com. The application steps are as follows:

To apply for a trial license, you need to provide zend.com with the ID of the computer you are using, or you can fill in the host ID on the application page (which is actually the MAC address of the NIC on your computer). The way to view computer IDs is as follows: Download a lmutil.z program from zend.com, extract the program Lmutil, run it, and it will produce a sequence string based on the hardware characteristics of the system. Fill this serial number into the host ID of the application License page, zend.com will generate a license for the user within 48 hours, download the license file named ZendEncode.dat, which can only be used on this computer.

1. The Zend Encode software package is also unzipped to the/usr/local/zend directory. After the decompression is complete, the directory has a Zendenc file, it is the "compiler".

2. Copy the license file to the/usr/local/zend directory for installation.

Installation of Zend Optimizer

Completed the installation of Zend encode to complete half of the task, to use the compiled PHP binary code, but also to install an interpreter--zend Optimizer, with its support, the compiled PHP binaries can be correctly executed.

Unlike Zend encode, Zend Optimizer is a free software, and its main function is to speed up the operation of PHP script files. According to Zend.com said, with Zend Optimizer optimization, the implementation of the program efficiency can be increased by 600%, after the author's simple test, the implementation efficiency is indeed improved a lot.
Install Zend Optimizer steps as follows:

1. Extract the Zend optimizer software package and copy zendoptimizer.so files 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 for the above update to take effect.

The use of Zend encode

Now that the preparations are complete, we write a simple php script, compile it with Zend encode, and see how it works. First write the simplest script to see if the compiled code can execute:

#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.

OK, compile successfully. However, the size of the compiled program is much larger than before.

Will Testencode. PHP is copied to the Web server's publishing directory and type Localhost/testencode on the browser. PHP, Wow! The compiled code can run successfully! Because we use the beta Zend Encode, a picture appears at the top of the page, indicating that this is a binary file produced by the Zend Encode trial package. In the official version of the software, the picture will not reappear.

Let's take a look at its execution efficiency. First write a small calculation program to roughly estimate:

[Compute. PHP]

?

R=time ();

for (121=0;121<1000000;121++) {

if ((121%20)!=0) {echo 121; echo ",";}

else {echo ' <br> ';}

}

=time ();

echo "<br>"; echo "It used:"; Echo-r; echo "seconds";

? >

This program in the execution, take the system time, complete and then take the system time, the difference of two values for the entire program to run the time required, first in the case of no compilation, and then executed with Zend encode compiled and then executed again. Comparison results: In the absence of compilation, the average time required to run is 19 seconds, the average compiled code execution time is 9 seconds, it seems that the implementation efficiency is improved a lot.


Related Article

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.