Use Zend Encode to write and develop PHP programs

  • 2020-03-31 20:26:17
  • OfStack

How does Zend Encode work
Anyone who USES PHP knows that it is a scripting tool, and programs written with it must be placed as source code on a Web server, so we cannot protect our source code. You know that any script is less efficient than a compiled binary with the same functionality. So if we had a tool that would help us program in PHP

I'll just translate it into binary code, which not only makes the execution more efficient,
The speed is also increased. If there is such a tool, it is
Kill two birds with one stone.

Now this is not a dream. This is what Zend Encode was developed for, which compiles scripts directly into binary code. With Zend Encode, you can compile your own PHP program and distribute it to many users without having to expose your source code. Compiled binaries can be read transparently by Zend Optimizer, which means that a client simply installs the Zend Optimizer on his server to execute a PHP program compiled by Zend Encode. The compiler contains part of the code for the Zend Optimizer, so the code is further optimized during compilation, which means the script is more efficient.

In a sense, Zend Encode is a "PHP compiler." However, it is not a compiler in the true sense of the word, because the compiled program can run out of the original compiled environment, and the compiled Zend Encode program needs the support of the Zend Optimizer. Just like compiled Java binaries, it requires support from the JVM. So, Zend Optimizer can be thought of as a virtual machine where PHP compiles good code. Anyway, they work together.
At present, Zend Encode supports operating systems: Solaris, Linux, FreeBSD and Windows. Zend Encode can be run directly, and you don't have to have PHP installed in your computer system.
Installation of Zend Encode

Download a software package first! Zend Encode is not free software, it costs money to use and is quite expensive. Fortunately, zend.com offers a trial-free 30-day trial of a software package. The package is available directly from www.zend.com. So go to www.zend.com and download the Zend Encode and Zend Optimizer packages. Next, download an authorization file, license. Since Zend Encode is an authorized product, users need to apply for a license from zend.com.
The application procedures 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, fill in the host ID on the application page (which is actually the MAC address of the network card on your computer). The way to view the computer ID is as follows: download an lmutil. Z program from zend.com, extract the program lmutil, run it, and it will generate a sequence string according to the system's hardware characteristics. Fill the serial number into the host ID on the license application page, and zend.com will generate a license for the user within 48 hours. The license file is called zendencode.dat, and it can only be used on this computer.

1. Unpack the Zend Encode package into /usr/local/zend as well. After unzipping, there is a new zendenc file in the directory, which is the "compiler".

2. Copy the license file to /usr/local/zend.

Installation of Zend Optimizer

Half the way through the installation of Zend Encode is to use the compiled PHP binaries and to install an interpreter, the Zend Optimizer, which allows the compiled PHP binaries to be executed correctly.
Unlike Zend Encode, Zend Optimizer is free software whose main function is to speed up PHP script files. According to Zend.com, with the optimization of Zend Optimizer, the execution efficiency of a program can be improved by 600%. After my simple tests, the execution 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 directory /usr/local/zend /lib.
2. Open the file /usr/local/lib/ php.ini and add the following two lines:
Zend_optimizer optimization_level = 15
Zend_extension = "/ usr/local/Zend/lib/zendoptimizer. So"
3. Restart the Apache server for the above updates to take effect.
The use of Zend Encode
Now that we're all set, let's write a simple PHP script and compile it using Zend Encode to see how it works. Write a simple script to see if the compiled code will work:
# vi test. PHP
< ? A 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.
The Compiling test. PHP...
The Done encoding test. PHP.
Optimizing... Done.
Saving... Done.
Ok, successful compilation. However, the compiled program is much larger than before.
Copy testencode.php to the publish directory of the Web server, and type localhost/ testencode.php in your browser. The compiled code runs successfully! Since we are using a trial version of Zend Encode, an image appears at the top of the page indicating that this is a binary generated by the trial Zend Encode package. Images will not be reproduced in the official version of the software.
Now let's see how efficient it is! First, write a small computer 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, after the completion of the system time, the difference between the two values is the entire program to run the required time, first in the case of no compilation of the execution, and then with Zend Encode after the compilation of the execution again. Comparison results: without compilation, the average running time is 19 seconds, and the average compiled code execution time is 9 seconds.

Related articles: