Let echo faster, so that the request processing of PHP, as soon as possible to end, the reason that echo is slow, is waiting for "write data" to return successfully, then a relatively simple way is to open the output cache,
Edit PHP.ini
4096 // bytes
You can also display the call Ob_start () in the script:
Ob_start (); Echo $huge _string ; // the other logic. Ob_end_flush ();
Note that the Ob_start will open a 4096-size buffer, so if huge_string is greater than 4096, it will not play an accelerating role.
Now, our echo will be executed "immediately" and returned. Because the data is temporarily written to our output cache. If buffer is large enough, the content will wait until the end of the script before it is sent to the client (strictly speaking, to webserver). But this does not solve the problem we have today, because the data in the end, still need PHP to send them to the client (regardless of webserver output buffer), the process is not finished, the request is not closed, PHP will not execute the DB destructor.
Our PHP to output 100K of data, then, our Apache output cache must be greater than 100K, or when Apache output cache is full, it will be sent to the client, and in this process, the execution of the ECHO will block the wait.
So, how do you modify Apache's output cache? We can use the Sendbuffersize configuration command in Apache's configuration file.
4096 // Note that it is byte
For a detailed description of the sendbuffersize, see Http://httpd.apache.org/docs/2.0/en/mod/mpm_common.html#sendbuffersize
Note: For other webserver with php-cgi mode, please check the relevant webserver manual for similar configurations.
Now, the echo of PHP, will directly give the content to Apache, PHP after the completion of execution, no longer wait for the content sent to the client to complete, and directly exit. The content will be sent to the client by Apache after the PHP process is complete. This accelerates echo's execution efficiency.
printf, print, file_put_contents ("Php://output") ... And so on, and Echo are the same.
Finally, to illustrate, to do so, just the original echo of the wait time, transferred to Apache, and did not really reduce the client to obtain the content of the time. It just accelerates the process of PHP processing, advance the time of PHP exit, so as to reduce the time of use of PHP resources, and indirectly increase the occupancy rate of resources.
Transfer from http://www.laruence.com/2011/02/13/1870.html
PHP improves the efficiency of ECHO, printf, print, file_put_contents and other output methods