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
The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment