PHP flush() ... Would This Be Useful?

For Articles relating to more than one ISC version
Post Reply
CharlieFoxtrot
Confirmed
Confirmed
Posts: 413
Joined: Sun Aug 09, 2009 1:23 pm

PHP flush() ... Would This Be Useful?

Post by CharlieFoxtrot »

In my never ending quest to fine-tune and optimize every aspect of the ISC code, I stumbled upon this page: http://developer.yahoo.com/performance/rules.html#flush

... which says:
Flush the Buffer Early

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:

Code: Select all

      ... <!-- css, js -->
    </head>
    <?php flush(); ?>
    <body>
      ... <!-- content -->

Yahoo! search pioneered research and real user testing to prove the benefits of using this technique.
A global search of the php code for ISC 4.07 shows that the "flush()" command is used mostly in admin-related scripts... and a couple of non-admin scripts whose purpose appears to be limited to things other than optimizing the store display.
  • viewfile.php
    admin\includes\classes\class.batch.importer.php
    admin\includes\classes\class.froogle.php
    admin\includes\classes\class.shipments.php
    admin\includes\classes\class.subscribers.php
    admin\includes\classes\class.upgrade.php
    admin\includes\classes\class.vendor.payments.php
    admin\includes\converter\class.converter.php
    admin\includes\converter\class.exporter.php
    includes\classes\class.account.php
MY QUESTIONS...

1) Does ISC construct (and output) pages in such a way that the "flush()" command would be useful?
2) If so, where should it go?

At first glance, it appears that a logical place to add the "flush()" command would be near the bottom of /includes/display/HTMLHead.php ... but it's difficult for me to determine if, at this point, ISC has actually created a complete <head> that's worth sending out early.

3) Or... am I obsessing about something that will produce gains that are so tiny it will hardly be worth the effort? (Tell me...you can be honest.)

~ Charlie
ISC 4.0.7

"... and let's be honest that whole "by design" thing is getting old too."
bus del cu
Posts: 58
Joined: Wed May 05, 2010 3:01 pm

Re: PHP flush() ... Would This Be Useful?

Post by bus del cu »

It doesn't look like 6.0.14 has many more instances of flush() than your version.
If Micro$oft made cars you would have to buy a new one every time they repainted the lines in the road.
Post Reply