file Flush the Buffer Early in Php

Topic Rating


25 Jan 2016 00:17 #1 by Trony

  • Administrator
  • Administrator
  • Location: Roma
  • Time Zone: UTC +2:00
  • Local Time: 11:13

  • Posts: 939
  • Profile views: 3260
  • Thank you received: 8

  • Register Date: 01 Jul 2008
  • Last login: 22 Sep 2021 22:50
  • Flush the Buffer Early in Php was created by Trony

    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:
    ... <!-- css, js -->
        </head>
        <?php flush(); ?>
        <body>
          ... <!-- content -->

    Music and Electronic Devices Designer. Drum and Bass Addict. Creative Mind as Lifestyle. Cat in past Life. Soccer, Ice Hockey and Snowboard Lover. Marxist.
    Sono Il Re sul Carro Danzante. Attraversando La Città Getto Via I Coriandoli Della Vostra Tristezza Regalando Passione Ed Estasi Nei Vostri Occhi.
    Follow Trony on: FusoElektronique | Facebook | Twitter | Soundcloud

    Please Log in or Create an account to join the conversation.

    Moderators: Trony

    You might also be interested...

    FusoElektronique - Pure Electronic Music.

    Community and Web Radio of Electronic Music since July 2008. Rome, Italy

    Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0) 2021.

    About us | Our team | Cookie Policy | Privacy Policy | Terms and Conditions | Contact us | Sitemap