By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,714 Members | 1,182 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,714 IT Pros & Developers. It's quick & easy.

PHP progress bar?

HaLo2FrEeEk
100+
P: 404
Ok, I know ths is possible, an example is here:

http://www.johnboy.com/php-upload-progress-bar/

It uses the ob_flush() and flush() functions of PHP. From what I've read, these functions have no effect if mod_gzip is enabled in your apache server. I'm on a shared hosting plan with Dreamhost and they have mod_gzip enabled, but you can request to have it turned off for certain subdomains. I did so, but it seems that it didn't have an effect. Here is my code:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. ob_start();
  3.  
  4. for ($i = 0; $i < 5; $i++) {
  5.   echo $i . "<br>";
  6.   ob_end_flush();
  7.   ob_flush();
  8.   flush();
  9.   sleep(1);
  10.   ob_start();
  11.   }
  12.  
  13. ob_end_flush();
  14. ?>
This should output numbers from 0 to 5 over 5 seconds, sequentially, WHILE the page is loading. Instead it just takes 5 seconds for the page to load and then outputs the whole thing at once.

I need to know how to make this work. I have a script that can take 30-45 seconds to run and I want something for my users to look at. Using Flash really isn't an option because I don't know flash. I COULD use AJAX and simply send a request to another script, but I'd like to try to avoid anything that requires Javascript.

Please, if you guys could help me out, I'd be super grateful!
May 8 '10 #1
Share this Question
Share on Google+
6 Replies


chathura86
100+
P: 227
please review that code properly

specially the APC part, which does the magic of sending the upload progress


Regards
May 8 '10 #2

HaLo2FrEeEk
100+
P: 404
Could you be a little more specific as to what I'm supposed to be looking at, everything looks right to me but it's not working, which is why I asked for help.
May 8 '10 #3

Markus
Expert 5K+
P: 6,050
Do you have APC enabled?
May 9 '10 #4

HaLo2FrEeEk
100+
P: 404
I don't know what APC is. It sounds familiar, but refresh my memory, please.
May 9 '10 #5

chathura86
100+
P: 227
All the details you need can be found in your tutorial

http://www.johnboy.com/php-upload-progress-bar/

for more info read the php manual

http://php.net/manual/en/book.apc.php

Regards
May 9 '10 #6

Markus
Expert 5K+
P: 6,050
The Alternative PHP Cache extension. Apparently it is necessary for this library to work.
May 9 '10 #7

Post your reply

Sign in to post your reply or Sign up for a free account.