Principle: Use ob_flush() and flush() to output the contents of the buffer in advance, and the browser can load this part in advance content, no need to wait for all output to complete before loading.
Divide the page content into small blocks, output one and then the next, so that users can see the page content as early as possible and optimize the user experience.
First of all, the content of head should be loaded first, and static content such as css and javascript should be loaded as early as possible. Therefore, flush() should be used to output after head.
Example: First output the head static content, then divide each into a chunk, and output it every second.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title> Big Pipe </title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <style type="text/css"> body{margin:0px; background:#CCCCCC;} p{text-align:center; margin:10px;} img{width:450px;} </style> </head> <?php cache_flush() ?> <body> <p><img src="/static/imghwm/default1.png" data-src="http://image.tianjimedia.com/uploadImages/2013/240/5CPOE4UZ2T40.jpg" class="lazy" alt="How to implement BigPipe chunked output through php" ></p> <?php cache_flush(); ?> <p><img src="/static/imghwm/default1.png" data-src="http://image.tianjimedia.com/uploadImages/2013/240/6893CY9XEQD1.jpg" class="lazy" alt="How to implement BigPipe chunked output through php" ></p> <?php cache_flush(); ?> <p><img src="/static/imghwm/default1.png" data-src="http://image.tianjimedia.com/uploadImages/2013/240/83H52SG02V32.jpg" class="lazy" alt="How to implement BigPipe chunked output through php" ></p> </body> </html> <?php function cache_flush($sec=1){ ob_flush(); flush(); usleep($sec*1000000); } ?>
Issues to note:
1. Try to use one output to output as much content as possible.
2. Try to load synchronously.
3. The more chunks are divided, the better. It depends on the actual demand.
4.ob_flush() and flush() must be used at the same time, because flush() will have no effect in some cases.
This article explains how to implement BigPipe block output through php. For more related content, please pay attention to the php Chinese website.
Related recommendations:
Related introduction to mysql optimization of insert performance
##How to use PHP common customization Method
How to encrypt/decrypt files using XOR via php
The above is the detailed content of How to implement BigPipe chunked output through php. For more information, please follow other related articles on the PHP Chinese website!

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi

PHPisusedforsendingemailsduetoitsbuilt-inmail()functionandsupportivelibrarieslikePHPMailerandSwiftMailer.1)Usethemail()functionforbasicemails,butithaslimitations.2)EmployPHPMailerforadvancedfeatureslikeHTMLemailsandattachments.3)Improvedeliverability

PHP performance bottlenecks can be solved through the following steps: 1) Use Xdebug or Blackfire for performance analysis to find out the problem; 2) Optimize database queries and use caches, such as APCu; 3) Use efficient functions such as array_filter to optimize array operations; 4) Configure OPcache for bytecode cache; 5) Optimize the front-end, such as reducing HTTP requests and optimizing pictures; 6) Continuously monitor and optimize performance. Through these methods, the performance of PHP applications can be significantly improved.

DependencyInjection(DI)inPHPisadesignpatternthatmanagesandreducesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itallowspassingdependencieslikedatabaseconnectionstoclassesasparameters,facilitatingeasiertestingandscalability.

CachingimprovesPHPperformancebystoringresultsofcomputationsorqueriesforquickretrieval,reducingserverloadandenhancingresponsetimes.Effectivestrategiesinclude:1)Opcodecaching,whichstorescompiledPHPscriptsinmemorytoskipcompilation;2)DatacachingusingMemc


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

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Linux new version
SublimeText3 Linux latest version
