½â¾önginxÏÂbigpipe²»ÉúЧµÄÎÊÌâ
ËùνBigPipe£¬Ö¸µÄÊÇFacebook¿ª·¢µÄÓÃÀ´¸ÄÉÆ¿Í»§¶ËÏìÓ¦Ëٶȵļ¼Êõ¡£±¾ÖÊÉϽ²£¬ÆäʵËü²¢²»ÊÇÐÂÊÂÎÔÀíÉϵÈͬÓÚYahooÔÚBest Practices for Speeding Up Your Web SiteÀïÌá³öµÄFlush the Buffer Early£¬²»¹ýBigPipeµÄʵÏÖ¸üÁé»î£¬ËùÒÔÓбØÒªÁ˽âÒ»¶þ¡£
ÎÒÃÇƽ³£ä¯ÀÀÍøҳʱµÄÌåÑéͨ³£ÊÇ´®Ðеģºä¯ÀÀÆ÷·¢ÆðÇëÇ󣬷þÎñÆ÷ÊÕµ½ºóäÖȾҳÃ棬ÔÚ´ËÆڼ䣬ä¯ÀÀÆ÷³ýÁ˵ȴý±ðÎÞÑ¡Ôñ£¬ÑÝʾ´úÂëÈçÏ£º
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>BigPipe Demo 3</title> <style type="text/css"> * {margin: 0; padding:0;} body {background-color:#fff;} div{border:2px solid #4F81BD; margin:30px; padding: 10px;} p {word-wrap:break-wrod; word-break:break-all; color: #666;} .red {color: #f00;} .blue {color:blue;} .green {color:green;} </style> <script> function render(nodeID,html){ document.getElementById(nodeID)[removed]=html; } </script> </head> <body> <div id="header"><p>Loading...</p></div> <div id="content"><p>Loading...</p></div> <div id="footer"><p>Loading...</p></div> <?php ob_flush(); flush(); sleep(1); //Ìî³ä»º³åÇø $header = str_pad('<span class="blue">111111</span>', 4096); ?> <script>render('header', '<p><?php echo $header;?><p>');</script> <?php ob_flush(); flush(); sleep(10); $content = str_pad('<span class="red">222222</span>', 4096); ?> <script>render('content', '<p><?php echo $content;?><p>');</script> <?php ob_flush(); flush(); sleep(10); $footer = str_pad('<span class="green">333333</span>', 4096); ?> <script>render('footer', '<p><?php echo $footer;?><p>');</script> <?php ob_flush(); flush(); ?> </body> </html>
×¢£º´úÂëÀïÓÃsleepÄ£Äâ·þÎñ¶ËºÄʱµÄ²Ù×÷¡£
Èç¹ûÎÒÃÇ°Ñ´®Ðиijɲ¢Ðеķ½Ê½ÄØ£¿Ã¿µ±·þÎñÆ÷Éú³ÉеÄÄÚÈÝÁ¢¿Ì·¢Ë͸øä¯ÀÀÆ÷£¬ä¯ÀÀÆ÷Á¢¿ÌäÖȾ£¬²»±ØµÈµ½½ÓÊÕµ½È«²¿Êý¾ÝÔÙ´¦Àí£¬ºÁÎÞÒÉÎÊ»áÌáÉýÓû§ÌåÑ飬´úÂëÈçÏ£º
ÌáÐÑһϣ¬´úÂë×îºóÔËÐÐÔÚApache + Mod PHP»·¾³£¬¾É°æ±¾Apache¿ÉÄÜÐèÒª¹Ø±ÕGZip¡£Èç¹ûÊÇNginx + PHP FastCGI»·¾³£¬ÒòΪfastcgi_buffersµÄ´æÔÚ£¬ÔËÐÐЧ¹û»á·ÇÄãËùÔ¸¡£
×¢Ò⣺ijЩä¯ÀÀÆ÷±ØÐë½ÓÊÕµ½Ò»¶¨³¤¶ÈµÄÄÚÈݲſªÊ¼äÖȾ£¬ËùÒÔ´úÂëÀïÓõ½ÁËstr_pad ½«Êä³öÄÚÈÝÇ¿ÖƵ½4096×Ö½Ú¡£
¸üУºÐ°æNginxÔö¼ÓÁËÒ»¸öfastcgi_bufferingÖ¸Á¿ÉÒÔÓÃÀ´¹Ø±ÕfastcgiµÄbuffer¹¦ÄÜ¡£
´úÂëÀïÓõ½ob_flushºÍflush°ÑÒ³Ãæ·Ö¿éˢлº´æµ½ä¯ÀÀÆ÷£¬´ËʱÈç¹ûʹÓÃFirebug²é¿´ÏìӦͷµÄ»°£¬»á·¢ÏÖ£ºTransfer-Encoding=chunked£¬Èç´ËÒ»À´ä¯ÀÀÆ÷¾Í¿ÉÒÔ·Ö¿éäÖȾÁË¡£
ʹÓÃBigPipe£¬ÏÈˢв¼¾Ö£¨Layout£©£¬È»ºó°´¿é£¨header£¬content£¬footer£©Ë¢ÐÂÏàÓ¦µÄJavascript´úÂ룬´Ó¶øʵÏÖÒ³ÃæÄÚÈݵÄÌî³ä¡£
BigPipeÖ®ËùÒÔʹÓÃJavascriptäÖȾҳÃ棬ÊÇÒòΪÕâÑùÒ»À´äÖȾҳÃæµÄʱºò£¬¾Í²»»á±»¿éµÄλÖÃÊø¸¿×¡£¬Èç¹ûÎÒÃǵķþÎñÆ÷Ö§³Ö¶àỊ̈߳¬ÄÇ Ã´¾Í¿ÉÒÔͬʱ´¦Àí¶à¿éÄÚÈÝ£¬ÄÄ¿éÏÈ´¦ÀíºÃ¾Í°ÑÄÄ¿éˢе½ä¯ÀÀÆ÷£¬¼´±ã²»Ö§³Ö¶àỊ̈߳¬·þÎñÆ÷Ò²¿ÉÒÔ°´ÕÕÄÚÈݵÄÖØÒª³Ì¶È·ÖÖ÷´ÎÏȺóäÖȾ£¬²»±Ø¾ÐÄàÓÚHTML´ú ÂëµÄÎïÀí˳Ðò¡£
´ËÍ⻹ӦעÒâÒ»ÏÂBigPipeºÍAjax¶þÕßµÄÇø±ð£¬¶ÔÓÚÒ»¸ö·Ö³ÉÈô¸É¸ö¿éµÄÒ³Ãæ¶øÑÔ£¬Èç¹ûʹÓÃAjaxµÄ»°£¬Ã¿Ò»¿é¶¼ÐèÒªµ¥¶À·¢ËÍÒ»¸öHTTP ÇëÇ󣬶øÈç¹ûʹÓÃBigPipeµÄ»°£¬²»¹ÜÓжàÉٿ飬¶¼½öÓÐÒ»¸öHTTPÇëÇó¡£ËùÒÔAjax¶Ô·þÎñÆ÷Ôì³ÉµÄѹÁ¦»áÊÇBigPipeµÄÈô¸É±¶¡£
×¢£ºBigPipe²»ÀûÓÚSEO£¬Ó¦ÓÃʱ¿Éͨ¹ýUser AgentÅжÏÇëÇóÊÇÈË»¹ÊÇËÑË÷ÒýÇ棬Èç¹ûÊÇÈ˵Ļ°£¬ÔòÓ¦ÓÃBigPipeäÖȾģʽ£¬Èç¹ûÊÇËÑË÷ÒýÇæµÄ»°£¬ÔòÓ¦Óô«Í³äÖȾģʽ¡£
²Î¿¼£ºFacebookÍøÕ¾µÄAjax»¯¡¢»º´æºÍÁ÷Ë®Ïߣ¨PDF£©¡£
ÍƼöÐÅÏ¢
- linuxÃüÁîѧϰ±Ê¼Ç£¨11£©£ºnlÃüÁî
- linuxÃüÁîѧϰ±Ê¼Ç£¨5£©£ºrmÃüÁî
- linuxÃüÁîѧϰ±Ê¼Ç£¨4£©£ºmkdirÃüÁî
- linuxÃüÁîѧϰ±Ê¼Ç£¨1£©£ºlsÃüÁî
- ½«CentosµÄyumÔ´¸ü»»Îª¹úÄڵİ¢ÀïÔÆÔ´
- ʹÓÃNginxÌí¼Óheader·ÀÖ¹ÍøÒ³±»frame
- linuxϼÓËÙscp´«Êä´óÎļþµÄËÙ¶È
- linuxϵͳÉ϶ÔnginxÈÕÖ¾·Ö¸î´¦Àí
- lnmp/nginxϵͳÕæÕýÓÐЧµÄͼƬ·ÀµÁÁ´ÍêÕûÉèÖÃÏê½â
- Í»ÆÆÊ®Íò²¢·¢µÄNginxµÄÅäÖü°ÓÅ»¯
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- ²éÕÒ²¢É¾³ý.svnĿ¼Îļþ
- redis ÆßÖÖÊý¾ÝÀàÐ͵ÄʹÓó¡¾°
- linux ÏÂÎļþ¸´ÖƵ½windowsÏÂÂÒÂëµÄ½â¾ö°ì·¨
- nginx³öÏÖ502 upstream sent too big he....
- linuxÏÂsudoÅäÖÃÏê½â
- linuxÃüÁîѧϰ±Ê¼Ç£¨15£©£ºtailÃüÁî
- linuxÃüÁîѧϰ±Ê¼Ç£¨14£©£ºheadÃüÁî
- linuxÃüÁîѧϰ±Ê¼Ç£¨13£©£ºlessÃüÁî
- linuxÃüÁîѧϰ±Ê¼Ç£¨12£©£ºmoreÃüÁî
- ¼ÓÃÜËã·¨±È½Ï3DES AES RSA ECC MD5 SHA1µÈ
ÆÀÂÛ