Home Backend Development PHP Tutorial A complete guide to improving PHP execution speed (Part 2)_PHP Tutorial

A complete guide to improving PHP execution speed (Part 2)_PHP Tutorial

Jul 21, 2016 pm 04:10 PM
php web Down Complete strategy content compression client implement promote use of speed


Compression of Web content (making it more "enjoyable" for your customers to use)

After the above two methods, I believe that the performance of your PHP application has been greatly improved. Now it is time to look at it from another aspect Considered: Download speed. If your application is only running within the company, and all customers use 100Mb/s Ethernet to connect to the server, this may not be a problem, but if some of your customers use slow modem connections, you need to consider Use content compression method. According to IETF specifications, most browsers support gzip content compression. This means that you can use gzip to compress the web content before sending it to the client's browser. The browser will automatically decompress the data when receiving it and allow the user to see the original page. Likewise, there are several different ways to compress the content of a web page.

mod_gzip is an Apache module provided free of charge by Remote Communications (http://www.phpbuilder.com/columns/www.remotecommunications.com), which can compress static web pages. It works just fine, you just need to compile it with apache (or use it as a DSO). People from Remotecommunications said it can also compress dynamic content, including mod_php, mod_perl, etc. But I tried it, and it doesn't seem to work. I read on the mod_gzip mailing list that this bug will be fixed in the next version (I think it will be version 1.3.14.6f). But you can still use it for static content compression.

But we also want to compress dynamic content, so we have to find another way. One way is to use class.gzip encode.php (http://leknor.com/code/). Just call this PHP class at the beginning and end of your PHP script to compress the content of your page. If your entire site requires such compression, you can call these functions in auto_prepend and auto_append in your php.ini file. It works pretty well, but on heavily loaded sites it obviously comes with a bit of overhead. To learn more about how it works, take a look at its class code (you'll need to at least compile PHP with zlib support). The author's instructions inside are also very detailed, so you can get everything you need to know.

Recently, I also saw an article about PHP output buffering. What it says is that PHP4.0.4 has introduced a new output buffer processing method-ob_gzhandler. Its function is the same as the class introduced above, but the difference is that you only need to use the following syntax in your php.ini. :

output_handler = ob_gzhandler ;

This will activate PHP's output buffering feature and compress everything it sends. For some special reasons, if you don't want to set it here and only change the default setting where needed (no compression), just modify the .htaccess file in the PHP source code directory that needs to be compressed. The syntax used is as follows:

php_value output_handler ob_gzhandler

...or call it directly in your PHP code, in the following way:

ob_start("ob_gzhandler" );

This method of output buffering is very good and does not bring additional system overhead to the server. I highly recommend you use this method. Its change can be illustrated by the following example. If the customer is using a 28.8K modem, after this process, he will think that he has suddenly switched to an ISDN access. One thing to note is that Netscape Communicator does not support image compression, so it will not be displayed. Therefore, unless all of your customers use Internet Explorer, you must disable compression of jpeg and gif images. There should be no problem with the compression of other files, but I suggest you test it, especially if the browser uses uncommon plug-ins or is a browser that is rarely used.

Other useful stuff...

Zend Technologies’ online store was launched on January 24 this year and sells some interesting PHP-related products. Including the aforementioned Zend Cache, Zend Encoder (simply put, it is a compiler for PHP code that can generate compiled classes so that you can sell to customers without worrying about leaking source code. In the web server that needs to run these classes (will use Zend Encoder Runtime to decode), Zend Ide (an integrated development environment for PHP with many powerful features), and support services for PHP developers.

Conclusion

Using the techniques mentioned in this article, you will be able to greatly improve the performance of your site, but please note the following points:

1. The bottleneck may not be there For PHP, you need to examine every object in the application (such as a database)

2. The performance of a web server is limited, so don’t think that poor performance is due to PHP, it may also be due to access The volume is large, your server needs to be upgraded, or consider using a load balancing system (it will cost a lot of money)

3. Don’t think that content compression is not important. In a 100Mb/s LAN, your PHP applications may perform well, but users with slow modems must be considered.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/314280.htmlTechArticleCompression of Web content (making it more "cool" for your customers to use) After the above two methods, I believe you The performance of PHP applications has been greatly improved, now it's time to consider it from another aspect...
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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

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

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

In this chapter, we are going to learn the following topics related to routing ?

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

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

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

See all articles