Taking tutorial submissions! Please email them to dave[AT]icemelon[DOT]com for review. Thanks!

Latest Tutorials
IceMelon IM: Add IM Functionality to phpBB [Misc] Want to add site-wide member IM to your phpBB community? Sure you do. Simple step-by-step instructions inside.

IceMelon IM: Add IM Functionality to vBulletin [Misc] Want to add site-wide member IM to your vBulletin community? Simple step-by-step instructions inside.

Crawl Your Site for PageRanks [PHP] So you know your site has a PageRank of 8. What about the PRs of all the inner pages? This tutorial will teach how you to automate the process of grabbing all these PRs.

Create CAPTCHA images [PHP] Worried about bots? Then create CAPTCHA images to prevent bots from taking advantage of your site.

Convert SHN and FLAC files to MP3 [Misc] Low on disk space and have an insensitive ear? Here are some steps to converting SHN and FLAC files to MP3 format.

[View All]

Become a sponsor for $15/month. Link is sitewide - PR5 homepage, 20+ PR4 pages, 90+ PR3 pages. Email dave[AT]icemelon[D0T]c0m.

Awesome Tutorials

Output While Script is Still Running
By dave

Do you have a script that takes a while to process? Wanna start outputting before the entire script finishes processing? Do you see no practicality to the questions I'm posing?

If you answered "yes" or "maybe" to this last question, then check out these links:
[http://www.marketleap.com/publinkpop/]
[http://farechase.yahoo.com/]
[http://www.tabpole.com]

The first link will check your site's link popularity. Do a search on your site and you will see an intermediate "please wait..." page where stats are being continuously outputted.

This second site is Yahoo!'s flight tickets search engine. Do a quick search and you will notice how the results are being constantly updated.

This last site is my own. It's a guitar, bass, & drum search engine. It works much like the first example.

Web pages developed with PHP always load at once after the entire script has processed. So, how does one output on the fly? The trick is PHP's output buffering functions, such as ob_flush. This function will "flush" out the current output buffer instead of waiting for the script to finish.

But, knowing the existence of these functions is barely a quarter of the battle! Believe me. It took me a long time to actually get these functions to "work." The reason being is that your browser (i.e. Internet Explorer) has its own buffer that needs to be filled. So, if your script flushes the output buffer but the browser's buffer isn't yet filled, nothing will be displayed!

The trick is to fillup the browser's buffer whenever you want to output. The following example, a PHP pre-loader, will illustrate this example.
<?
ob_implicit_flush(true);
for($i=0; $i<8; $i++) {
    echo "<span style='width:8px; background:blue'> </span>";
    for($k = 0; $k < 40000; $k++)
        echo ' '; // extra spaces to fill up browser buffer
}
?>

Breakdown
First, I called ob_implicit_flush to turn implicit flush on. This function will flush the output buffer automatically everytime something is echoed. The FOR loop will print out 8 blue bars, one at a time. The inner FOR loop prints out 40,000 empty spaces to fill up the browser's buffer.

Caveats
  • If you use ob_flush, you must call flush afterwards. Order matters!
    ob_flush();
    flush();

  • Avoid creating HTML tables. If an HTML table is not closed, whatever's inside will NOT be outputted.
Other Related Functions:
ob_start
ob_end_flush
ob_get_contents
ob_get_length
ob_get_clean

Alright, that's a wrap. I hope this tutorial has saved you time & headaches.

P.S. Check out my new site TheManWhoSoldtheWeb.com, where I publish guides and scripts on Internet Marketing and SEO. Here is a limited time freebie: the Rapid Google Indexer.


» Bookmark this Tutorial
» Bookmark IceMelon
Icemelon -- Output While Script is Still Running -- PHP, CSS, Javascript Tutorials, & More!
  © 2005-2010 Icemelon.com   Email: dave[AT]icemelon[D0T]c0m