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