Home Backend Development PHP Tutorial Compile PHP programs using ZendEncode_PHP tutorial

Compile PHP programs using ZendEncode_PHP tutorial

Jul 13, 2016 am 10:38 AM
php one use principle Work of Know program compile

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



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<1000000;$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 of this Website
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

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 Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

7 PHP Functions I Regret I Didn't Know Before 7 PHP Functions I Regret I Didn't Know Before Nov 13, 2024 am 09:42 AM

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

See all articles