Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP Flush Function

Status
Not open for further replies.

Jillq

Programmer
Jun 28, 2008
30
US
What do you think of this I found on the internt:

What do you think of this?

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:

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



How well does it work? Can you put in an ordinary page of HTML and CSS? If so can you put in that exact code above ("js"?)

Thanks,

Jillq
 
I don't think a couple of milliseconds is going to make much difference.

Still if you wanted to use it, you would need to have a web server that actually supports PHP, and either change your pages to PHP pages. Or configure your server to parse html pages through the PHP engine.

Now if your pages are that big that you need to actually flush them, then actually having to parse large amounts of HTML in search of a PHP section to run and then returning all that to the browser will undoubtedly take time to do.
So any real benefit you may gain form prematurely flushing, will be negated by the time it takes to parse the pages through the PHP engine.



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Vacunita,
I don't think I'll use that function after all.

Thanks,

Jillq
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top