Online editing School: PHP website basic optimization method _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Online editing School: basic PHP website optimization method. Brief the following basic skills to make your PHP website run faster. 1. use GZip to add the following code to the top of each PHP page :? Phpob_start (ob_gzhandler );? Introduction to this generation

The following basic skills allow your PHP website to run faster.

1. use GZip

Add the following code to the top of each PHP page:

  

After this code is used, the server compresses all the code that needs to be sent to the client and decompress it in the browser to speed up website operation. This function can also save website space traffic.

2. do not abuse Javascript or Ajax

Use Javascript and Ajax only when necessary. do not abuse them. Some websites use too many unnecessary Ajax animations or use Ajax to load useless parts. In this way, Javascript files will become very large, but there are actually many other solutions to implement these functions.

3. images, header files, and HTTP requests

This is the most important part of this article. The more images, external files, and CSS style files referenced by a webpage, the slower the webpage is to load. Take some time to reduce image files and other external files so that they can be loaded more quickly. In addition, each time an image or external file is loaded, an HTTP request is generated, which will delay the loading time. You can use the following methods to compress webpage files, JS files, and CSS style files:

Webpage files: use GZip. See Article 1.

JS file: This website can effectively reduce the size of JS files

CSS file: This website can reduce the size of CSS files.

4. restrict MySQL queries

Each request to the database slows down the webpage loading speed. It is difficult for network developers to control this point, but some details can be optimized. For example, do not use the following code when selecting a database record:

SELECT * FROM database

Instead, use:

SELECT id, name, date, author, etc, blah, blah FROM database

This will consume less query time and reduce server load.

5.. php extension

Some people think that saving the JS file as filename.js.php and saving the CSS file as stylesheet.css. php will reduce the loading time, but I didn't notice the difference. Of course, if your website is slow, you can try this method. Of course, you need to use include () in each php file to load these files.

Go to this website and check your website. it will give you some suggestions on how to optimize your website. This function is used every time I create a new page.

Go to this website and check your website. it will give you some suggestions on how to optimize your website. This function is used every time I create a new page.

Tips: these basic skills can make your PHP website run faster. 1. use GZip to add the following code to the top of each PHP page :? Phpob_start (ob_gzhandler );? Use this generation...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.