PHPKB Knowledge Base Software Knowledge Base Software Demo Buy PHPKB Software 
PHPKB Knowledge Base Software Knowledge Management Software  
Knowledge Base Home Knowledge Base Home | Knowledge Base Glossary Glossary | Contact Us Contact Us
Home > All Categories > Computers & Information Technology > Internet and WWW > Web Design & Development
Title

Progress Bar in PHP - Implement a progress bar with PHP

Almost every PHP developer feels the need to display a progress meter or progress bar in PHP at some point in their life when large amount of data processing is done on the server either in the form of file uploading or bulk insert/update operations of database queries are being performed however not may of them know that PHP has a big limitation that does not allow to access raw data while code execution is being done.

Good news is that we can achieve our goal using PHP?s flushing buffer to create a progress bar for large PHP applications. You can use the flush() function to push more data to the browser while the php script is running using the following code. This data being elements for small pieces of the progress bar, you can rather easily have a universal solution for all heavy scripts.

<?php
ob_end_flush(); // This is to clear the buffer and it should be called at start
?>
<html>
<head>
<title>PHP Progress Bar Example</title>
<script type="text/javascript">
<!--
function DisplayProgress(prog_value,div_id)
{
document.getElementById(div_id).innerHTML = prog_value + "% done out of 100%";
}
-->
</script>

</head>
<body>
<div id="progbar"></div>
</body>
</html>
<?php
$total_count = 100000;
for($i=0; $i<=$total_count; $i=$i+10)
{
$progress_made = ($i/$total_count)*100;
print "<script type="text/javascript">
DisplayProgress(".$progress_made.",'progbar');
</script>n";
flush(); // Push the new data to browser
}
?>

Please note that on some occasions, the webserver, proxy or the client browser can buffer data no matter what you do, so this will not work 100% for everyone at every situation. Still, this is a great idea.

A total of 91 users are reading this article.
Posted by: Administrator This question has been viewed 1683 times so far.

Want More?
Would you like to be notified when new articles are added to our knowledgebase? Subscribe to our Feed and get instant notifications when new articles are added to the knowledgebase.

Click Here to view all the questions in the Web Design & Development category.
Attachments File Attachments
There are no files attached to this question/article.
How helpful was this article to you?
User Comments User Comments Add Comment
There are no user comments for this article. Click Here and be the first to post a comment.
Related Questions Related General Knowledge Questions
There are no other questions related to this question.
Information Additional Information
Article Number: 607
Created: 2008-05-09 3:57 AM
Rating: 3 Stars
 
options Article Options
Email to Friend
Export to PDF format Export to PDF File
del.icio.us Bookmark del.icio.us Bookmark
Reditt Bookmark Reditt Bookmark
Digg Bookmark Digg Bookmark
Stumble Stumble It
Subscribe to Article
Twitter
Feedburner Stay Informed by Email
 
Resources Useful Links
 
Search Knowledge Base Search Knowledge Base
 
 

Powered by PHPKB Knowledge Base Software