PHP implements BigPipe chunked output_PHP tutorial
In the Yahoo system's best practices, it is recommended to output static content as early as possible, and call flush after the head, so that the browser can load static resources as early as possible, including scripts, styles, images (javascript, css, images are generally external In the form of a chain), etc., if there are multiple data sources or APIs that need to be called in the background, try to complete one output one by one, and assemble the page on the front end through js to achieve the effect of optimizing the user experience. The time the user waits is not worth the time. The fast wooden board with the shortest barrel.
Here is the quote:
Flush the Buffer Early
tag: server
When users request a page, it can take anywhere from 200 to 500ms for the backend server to stitch together the HTML page. During this time, the browser is idle as it waits for the data to arrive. In PHP you have the function flush( ). It allows you to send your partially ready HTML response to the browser so that the browser can start fetching components while your backend is busy with the rest of the HTML page. The benefit is mainly seen on busy backends or light frontends.
A good place to consider flushing is right after the HEAD because the HTML for the head is usually easier to produce and it allows you to include any CSS and JavaScript files for the browser to start fetching in parallel while the backend is still processing.
Example:
...
...
The BigPipe technology proposed by Facebook implements this idea in a more concrete way. The general idea is to decompose web pages into small pieces called Pagelets, and then establish pipelines through Web servers and browsers to manage their operation at different stages.
Do a small test under php,
';ob_flush();flush();sleep(2);echo "b";?>
The results can be seen under IE (7, 8). Regardless of the size of the output content, the effect can be seen. "b" is output after 2 seconds. In Firefox and Chrome, both pieces of text are displayed after 2 seconds. Description The browser has cached it. After experiments, the cache size is 1024, which is exactly 1k. This is also an optimization done by the browser. It can be seen from the return header that when outputting in segments, the return packet does not go through gzip.
Through wireshark, you can see that the background output is indeed chunked one by one. It seems that the browser has done the work. I guess: the cache size should be 1024B or the MTU size (more than 1400B, depending on the network conditions). The first paragraph of output increases to At 1024, Chrome and Firefox started to perform normally, and the js, css and images in the page started loading after the first paragraph was downloaded.
Questions to think about:
1. Transmission efficiency, try to use one transmission to transmit as many things as possible, adjust according to the MTU size;
2. Synchronous loading. The first thing sent should be loaded synchronously as much as possible. You need to pay attention to the number of domain names that different browsers can load synchronously. You need to consider the block loaded by javascript. For content that does not need to be executed immediately, you can add defer or Simply comment it out and wait for the page to be completed before eval comes in;
3. Scope of application. Each technology has its own applicable scenarios. It is more suitable for applications that need to access multiple APIs in the background. For example, social networking websites, searches, etc. are already displayed in about 100ms. It is purely for fun. Technology is meaningless, and the more chunked, the better. Appropriate and similar ones are best combined;
4. ob_flush and flush are best used in pairs. In some cases, flush has no effect.
Reference:
http://www.BkJia.com/kf/201202/118114.html
http://developer.yahoo.com/performance/rules.html#flush
http://www.BkJia.com/kf/201202/118116.html
http://www.BkJia.com/kf/201202/118117.html
http://baike.baidu.com/view/4601904.htm
http://www.BkJia.com/kf/201202/118118.html

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.
