can PHP handle high concurrency? PHP high concurrency Solution

Source: Internet
Author: User
Tags echo date
PHP in the process of how to deal with high concurrency problems, and then we take a specific look at the PHP high concurrency of a solution.

Let's take a look at PHP's execution process on the server: when the user requests the server PHP file, the server will parse the PHP file, followed by parsing, and then running. When a PHP file has a content output, it passes through the server's PHP buffer, which is then passed to the client via TCP. (buffer is in fact buffers, a memory address space, mainly used to store data regions)

It can be seen that when a user accesses a static page directly, the server's response time is generally shorter than the time it takes to access the dynamic file. If we can convert the dynamic files that the user will access to a static file, it will speed up the user's access to the page (get the speed of the page). Of course, we should pay attention to the static application scenario, the static page is mainly applied to those pages where the content of the page changes infrequently.

For static, the static of PHP is divided into: pure static and pseudo-static. The pure static is divided into: local pure static and all pure static. This will be all pure static.

One of the ways the page is static is by using the buffer ob that comes with PHP:

The following is a simple implementation of page buffering

<?php//can be cached based on the front-end pass parameter cookie, $id = $_get[' id '];//set buffer file name $cache_name = MD5 (__file__). '-' . $id. '. html ';//Expiration Time $life = 3600;//Determine if the file exists and whether it expires if (file_exists ($cache _name) && (Filectime ($cache _name) > Time ( )-$life)) {    include $cache _name;    Exit;} Open buffer Ob_start (), Echo date (' y-m-d h:i:s '), $content = Ob_get_contents (); Ob_end_clean ();//write to buffer file file_put_contents ( $cache _name, $content); Echo $content;

In addition to the above methods, we can use some of the framework's own buffer mechanism to achieve

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.