Compiling PHP programs using Zendencode _php tutorial

Source: Internet
Author: User
Tags php compiler
First, the working principle of Zendencode

People who use PHP know that it is a script programming tool, the program written by it, must be placed in the form of source code on the Web server, so we can not protect their own source. And you all know that the execution efficiency of any one script is slower than that of compiled binary code with the same functionality. Well, if there is a tool that can help us to compile the PHP program into binary code, so that not only the implementation of improved efficiency, and speed of operation. If there was such a tool, it would take two.

Just now, the release of Zendencode was developed for this purpose. Zendencode can directly compile the script into binary code. With the Zendencode, 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 Zendencode 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 a sense, Zendencode is a "PHP compiler". However, it is not a real compiler, the real compiler will run out of the original compilation environment, and Zendencode compiled programs, but also have zendoptimizer support, as is the compiled Java binary code, it should have a JVM to run. Therefore, Zendoptimizer can also be seen as PHP compiled code of the virtual machine. In any case, it is such a thing, they need to be used in conjunction with each other.

Currently Zendencode supported operating systems are: Solaris,linux,freebsd and Windows. Zendencode can be run directly, you do not have to install PHP in your system.


Second, the installation of Zendencode (this article in the Linux environment installation as an example explanation)

Go ahead and download a package! Zendencode is not free software, it has to pay, 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 http://www.zend.com/. So, first to http://www.zend.com/download Zendencode, Zendoptimizer package. Second, to download an authorization file, that is license. Since Zendencode is a licensed product, users are required to request a license from zend.com. The application card 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, that is, the host ID you want to fill in the Application page (which is actually the MAC address of the network card on your computer). The method of viewing the computer ID is as follows: Download a lmutil.z program from zend.com, extract the program Lmutil after decompression, run it, will produce a sequence string according to the hardware characteristics of the system. Put some serial numbers into the HostID 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 is the only one that can be used on your computer.

1, the Zendencode software package is also extracted in the/usr/local/zend directory. 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

Installation is complete.

Third, the installation of Zendoptimizer

Completed the installation of Zendencode, only completed half of the task, to use the compiled PHP binary code, but also to install an interpreter-zendoptimizer, with its support, the compiled PHP binaries can be executed correctly.

Unlike Zendencode, Zendoptimizer is a free software, its main function is to accelerate the operation of PHP script files, according to Zend.com said, with the Zendoptimizer optimization, program execution efficiency can be increased by 600%, after the author's simple test , the efficiency of implementation has indeed improved a lot.

The installation Zendoptimizer steps are as follows:

1. Unzip the Zendoptimizer software 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 for the above update to take effect


Iv. Use of Zendencode

Well, the above preparation is all done, now write a simple php script, use Zendencode compile, see how the effect, good, first write a simple script, 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©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.

Copy the testencode.php to the Web server's publish directory, type http://localhost/testencode.php on the browser, wow, the compiled code will run successfully! Because we use a trial version of the Zendencode, so , a picture appears at the top of the page stating that this is a binary file produced by the Zendencode trial package. As shown in the following:


If you purchase a full version of the user, the above icon will not be reproduced.

Let's take a look at the efficiency of its execution. First, write a small calculation program rough estimate: compute.php


$t =time ();

for ($i =0; $i <1000000; $i) {

if (($i)!=0) {echo $i; echo ",";}

else {echo '
";}

}

$t 1=time ();

echo "
"; echo "It used:"; echo $t 1-$t; 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 entire program to run the time required, first in the case of not compiled, and then executed again with Zendencode compiled and then executed again. Comparing results: Without compiling, the average time to run is 19 seconds, the compiled code executes 9 seconds on average, and it seems that the execution efficiency is improved a lot.

Five, attention

Due to the rapid development of PHP, its version number is also updated quickly, if you follow the above practice, but, your browser display is a garbled, then the description, your PHP and the version of the Zendoptimizer you are using does not match, Just re-download the corresponding Zendoptimizer can solve the above garbled problem. Also, pay attention to the version of the package you downloaded, in the Linux environment, there are glibc and libc points. Redhat version 6 should download the GLIBC type of package.

http://www.bkjia.com/PHPjc/735103.html www.bkjia.com true http://www.bkjia.com/PHPjc/735103.html techarticle First, Zendencode working principle people who use PHP know that it is a script programming tool, written by the program, it must be in the form of source code on the Web server, so we can not protect ...

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