search
HomeBackend DevelopmentPHP TutorialCompile PHP programs using ZendEncode_PHP tutorial

1. How ZendEncode works

Everyone who uses PHP knows that it is a script programming tool. The program written by it must be placed on the web server in the form of source code, so we cannot protect it. own source code. And everyone knows that the execution efficiency of any script program is relatively slow compared with the compiled binary code with the same function. So it would be great if there was a tool that could help us compile programs written in PHP into binary code. This would not only improve the execution efficiency, but also speed up the running speed. If there really was such a tool, it would be a two-for-one thing.

Just in time, the just-released ZendEncode was developed for this purpose. ZendEncode can directly compile scripts into binary code. With ZendEncode, you can compile the PHP program you wrote and distribute it to many users without exposing your source code. The compiled binary code can be transparently read by zend Optimizer. That is to say, the customer can execute the PHP program compiled by ZendEncode as long as he installs Zend Optimizer on his server. The compiled program contains part of the Zend Optimizer code, 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, ZendEncode is a "PHP compiler". However, it is not a real compiler. A real compiler will run independently of the original compilation environment. Programs compiled by ZendEncode also need the support of ZendOptimizer, just like compiled java binary codes. , which requires a JVM to run. Therefore, ZendOptimizer can be regarded as a virtual machine for PHP compiled code. In any case, it is just such a thing, they have to be used in conjunction with each other.

The operating systems currently supported by ZendEncode are: Solaris, Linux, FreeBSD and Windows. ZendEncode can be run directly, and php does not have to be installed on your system.


2. Installation of ZendEncode (this article uses the installation in the Linux environment as an example)

Download a software package first! ZendEncode is not free software, and you have to pay to use it , and the price is quite high. Fortunately, zend.com offers a trial package that allows users to try it for free for 30 days. This package is available directly from http://www.zend.com/. Therefore, you must first download the ZendEncode and ZendOptimizer software packages from http://www.zend.com/. Secondly, you need to download an authorization file, that is, license. Since ZendEncode is an authorized product, users need to apply for a license from zend.com. The steps to apply for a card 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 to be filled in on the application page (actually the host ID on your computer The MAC address of the network card), the method to check the computer ID is as follows: Download a lmutil.z program from zend.com, decompress it to get the program lmutil, run it, a sequence string will be generated according to the hardware characteristics of the system. Fill in these serial numbers into the hostid on the license application 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. Unzip the ZendEncode software package in the /usr/local/Zend directory. After decompression is completed, there is an additional zendenc file in the directory, which is the "compiler".

2. Copy the license file to the /usr/local/Zend directory

The installation is complete.

3. Installation of ZendOptimizer

After completing the installation of ZendEncode, only half of the task is completed. You need to use the compiled php binary code and install an interpreter-ZendOptimizer. With it support, the compiled php binary can be executed correctly.

Unlike ZendEncode, ZendOptimizer is a free software. Its main function is to speed up the running of php script files. According to Zend.com, with the optimization of ZendOptimizer, the execution efficiency of the program can be increased by 600%. After The author's simple test has indeed improved the execution efficiency a lot.

The steps to install ZendOptimizer 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 to make the above updates take effect


4. Use of ZendEncode

Okay, all the above preparations are completed , now write a simple php script, use zendEncode to compile it, and see the effect. Okay, first write the simplest script and see if the compiled code can be executed:

#vi test.php

Phpinfo(); ?>

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.

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

Copy testencode.php to the release directory of the web server, type http://localhost/testencode.php on the browser, wow, the compiled code can run successfully! Since we are using it for trial use version of ZendEncode, so a picture will appear at the top of the page, indicating that this is a binary file generated by the ZendEncode trial software package. As shown in the picture below:


For users who have purchased the official version, the above icon will not reappear.

Let’s take a look at its execution efficiency! First, write a small calculation program to roughly estimate: compute.php



$t=time ();

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

else { echo "
";}

}

$t1=time();

echo "

?>

When this program is executed, it takes the system time. After completion Then take the system time. The difference between the two values ​​is the time required for the entire program to run. First execute it without compilation, then compile it with ZendEncode and execute it again. Mutual comparison results: without compilation, the average running time is 19 seconds, and the average execution time of the compiled code is 9 seconds. It seems that the execution efficiency has been improved a lot.

5. Note

Due to the rapid development speed of PHP, its version number is also updated very quickly. If you follow the above steps, but your browser display is a mess. Garbled characters, then it means that your php does not match the ZendOptimizer version you are using. Just re-download the corresponding ZendOptimizer to solve the above garbled code problem. In addition, pay attention to the version of the software package you download. In the Linux environment, there are glibc and libc. Redhat 6 and later versions should download glibc type software packages.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/735103.htmlTechArticle1. Working principle of ZendEncode Anyone who uses PHP knows that it is a script programming tool written by The program must be placed on the Web server in the form of source code, so we cannot protect...
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP Dependency Injection Container: A Quick StartPHP Dependency Injection Container: A Quick StartMay 13, 2025 am 12:11 AM

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Dependency Injection vs. Service Locator in PHPDependency Injection vs. Service Locator in PHPMay 13, 2025 am 12:10 AM

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHP performance optimization strategies.PHP performance optimization strategies.May 13, 2025 am 12:06 AM

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHP Email Validation: Ensuring Emails Are Sent CorrectlyPHP Email Validation: Ensuring Emails Are Sent CorrectlyMay 13, 2025 am 12:06 AM

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

How to make PHP applications fasterHow to make PHP applications fasterMay 12, 2025 am 12:12 AM

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

PHP Performance Optimization Checklist: Improve Speed NowPHP Performance Optimization Checklist: Improve Speed NowMay 12, 2025 am 12:07 AM

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

PHP Dependency Injection: Improve Code TestabilityPHP Dependency Injection: Improve Code TestabilityMay 12, 2025 am 12:03 AM

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

PHP Performance Optimization: Database Query OptimizationPHP Performance Optimization: Database Query OptimizationMay 12, 2025 am 12:02 AM

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function