Use Zend Encode to write a development PHP program

xiaoxiao2021-03-06  38

People who use PHP know that it is a script programming tool that is written with the program that must be placed on the web server in the source code, so we can't protect your source code. Everyone knows that the execution efficiency of any script is compared to the compiled binary code with the same function, it is relatively low. Then if you have a tool to help us compile the programs written in PHP into binary code, it is not only improved, but also improves.

Running speed is also accelerated. If there is such a tool, it is two.

Now this is not a dream, Zend Encode is developed for this, it can directly compile scripts into binary code. With Zend Encode, you can write your own PHP program, compile, and distribute to many users, and don't open your own source code. Compiling the binary code can be read by Zend Optimizer, that is, the customer can perform a PHP program compiled by Zend Encode as long as the customer installs Zend Optimizer on his server. The compiler contains partial code of Zend Optimizer, so the program code is further optimized during the compilation process, which means that the execution efficiency of the script is improved.

In a certain sense, Zend Encode is a "PHP compiler". However, it is not a true compiler because the programs that are really compiled can be separated from the original compilation environment, and the program compiled by Zend Encode requires the support of Zend Optimizer. Just like compiled Java binary code, JVM support is required. So, Zend Optimizer can be seen as a virtual machine that is compiled by PHP. Anyway, they have to use each other.

The operating system currently supported by Zend Encode has: Solaris, Linux, FreeBSD and Windows. Zend Encode can be run directly, and there is not necessarily to install PHP in the computer system.

Zend Encode installation

Let's go to download a package! Zend Encode is not free software, use it to pay, and the price is quite high. Fortunately, Zend.com provides a package for trial, and users can trial for 30 days. This package can be obtained directly from www.zend.com. So, first download the Zend Encode, Zend Optimizer package to www.zend.com. Second, to download a license file license. Since Zend Encode is an authorized product, it is necessary to apply for a license from Zend.com. The application steps are as follows:

To apply for a trial License, you need to provide the ID of the computer you are using to zend.com, that is, fill in the Host ID in the application page (actually the MAC address on your computer). The method of viewing the computer ID is as follows: Download a LMUTIL.Z from Zend.com, decompress the program LMUTIL, run it, it will generate a sequence string according to the hardware feature of the system. In the Host ID of the application license page, Zend.com generates a license for the user within 48 hours, download this license file, the file name is Zendencode.dat, which can only be used on this computer .

1. Unzip the Zend Encode package to the / usr / local / zend directory. After the decompression is completed, there is a more zendenc file in the directory, which is the "compiler".

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

Zend Optimizer installation

After completing the installation of Zend Encode, he completes half of the task. To use the compiled PHP binary code, you have to install an interpreter - Zend Optimizer, with its support, compiled PHP binary files can be properly executed . Unlike Zend Encode, Zend Optimizer is a free software, its main function is to accelerate the operation of the PHP script file. According to Zend.com, there is an optimization of Zend Optimizer, and the execution efficiency of the program can be increased by 600%. After the author's simple test, the implementation efficiency is indeed a lot.

Installing the Zend Optimizer steps as follows:

1. Unzip the Zend Optimizer package, copy the ZendOptimizer.so file to the / usr / local / zend / lib directory.

2. Open the /usr/local/lib/php.ini file, 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 update take effect.

Zend Encode

Now preparing all the completed, we write a simple PHP script, use Zend Encode to compile, see how the effect. First write a simple script, see if the compiled code can be executed:

#vi test.php

Compile it:

# [root @ Mail Zend] # ./zendenc test.php tester-name.php

Zend Encoder Unlimited (Test Drive) v1.1.0 (c) Zend Technologies, 1999-2000

Licensed to: xqkred.

Compiableing test.php ...

Done Encoding Test.php.

Optimizing ... DONE.

Saving ... done.

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

Type LocalHost / Testencode.php on the browser on the browser to copy TESTENCODE.PHP to the publishing directory of the web server. Wow! The compiled code can be successfully runned! Since we use it is a trial version of Zend Encode, a picture will appear on the top of the page, indicating that this is a binarily generated by the Zend Encode Trial Package. In the official version of the software, the picture will not reproduce it.

Let's take a look at its execution efficiency! First write a small computing program rough estimate:

[compute.php]

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";

?>

转载请注明原文地址:https://www.9cbs.com/read-66776.html

New Post(0)