When we collide use Zend encode to write PHP program development

Source: Internet
Author: User
Tags download zend php compiler
How the Zend encode works
People who use PHP know that it is a scripting tool that uses it to write programs that must be placed on the Web server in the form of a source code, so we cannot protect our own sources. We all know that the execution efficiency of any one script is relatively low compared with compiled binary code with the same function. So if there's a tool that can help us write a program written in PHP
It's good to translate into binary code so that not only does the efficiency increase,
The speed of operation is also accelerated. If there was such a tool, it would be
It's double benefit.
Now this is not a dream, Zend encode is developed for this purpose, it can directly compile the script into binary code. With the Zend Encode, you can write your own PHP program, compiled and distributed to many users, rather than exposing their source program code. The compiled binary code can be read transparently by the Zend Optimizer, which means that the client can execute a PHP program compiled by Zend encode just by installing Zend Optimizer on his server. The compiler contains part of the code for Zend Optimizer, so the program code is further optimized during the compilation, which means that the execution of the script is more efficient.
In some sense, Zend encode is a "PHP compiler". However, it is not a true compiler, because the actual compiled program can be run out of the original compilation environment, and Zend encode compiled program, need to have Zend Optimizer support. Just like the compiled Java binaries, you need the support of the JVM. So, Zend Optimizer can be seen as a virtual machine where PHP compiles good code. In any case, they need to be used in conjunction with each other.
Currently, Zend encode supports the following operating systems: Solaris, Linux, FreeBSD, and Windows. Zend encode can be run directly, the computer system is not necessarily to install PHP.
Installation of Zend encode
Go ahead and download a package! Zend encode is not free software, it pays for it, and the price is quite high. Fortunately, Zend.com offers a trial-ready package that users can try for free for 30 days. This package can be obtained directly from the www.zend.com. So, first to www.zend.com download Zend Encode, Zend Optimizer package. Second, to download an authorization file license. Since Zend Encode is a licensed product, users are required to request a license from 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, and then fill in the host ID on the application page (which is actually the MAC address of the network card on your computer). The method for viewing the computer ID is as follows: Download a lmutil.z program from zend.com, extract the program Lmutil, run it, and it will generate 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 this license file, the file name is ZendEncode.dat, it can only be used on this computer.
1. Extract the Zend Encode package to the/usr/local/zend directory as well. After the decompression is complete, there is a Zendenc file in the directory, it is the "compiler".
2. Copy the license file to the/usr/local/zend directory to complete the installation.
Installation of Zend Optimizer
Completed the installation of Zend encode, only completed half of the task, to use the compiled PHP binary code, but also to install an interpreter--zend Optimizer, with its support, compiled PHP binaries can be executed correctly.
Unlike Zend encode, Zend Optimizer is a freeware, and its main function is to speed up the operation of PHP script files. According to Zend.com said, with the optimization of Zend Optimizer, the execution efficiency of the program can be increased by 600%, after the author's simple test, the implementation efficiency is indeed improved a lot.
The steps to install Zend Optimizer are as follows:
1. Unzip 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_extension= "/usr/local/zend/lib/zendoptimizer.so"
3. Restart the Apache server for the above update to take effect.
Use of Zend encode
Now that the preparation is complete, let's write a simple php script and compile it with Zend encode to see how it works. Write one of the simplest scripts 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.
OK, compile successfully. However, the compiled program size is much larger than before.
Will Testencode. PHP is copied to the Web server's publishing directory, type Localhost/testencode on the browser. PHP, Whoa! The compiled code will run successfully! Since we are using a trial version of Zend Encode, a picture appears at the top of the page stating that this is a binary file produced by the Zend Encode trial package. In the official version of the software, the images will not reappear.
Let's take a look at its execution efficiency! First, write a small calculation program with a rough estimate:
[Compute. PHP]

Copy the Code code 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";

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

The above describes when we collide with Zend Encode development PHP program, including when we collide aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

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