/    Sign up×
Community /Pin to ProfileBookmark

Progress Bar Issue

Hi, I’m trying to implement a progress bar that supposedly works for someone else ([URL=”http://www.webmasterworld.com/javascript/3995459.htm”]forum link[/URL]). Every time I try this, it seems to wanna perform the actual script/or mock script(sleep func) BEFORE showing the progress bar.

Any clue what’s going on here?

[CODE]
<?php

echo ‘<h1>Logging into system…</h1>’;
echo ‘<div id=”progress” style=”width: 100px;border: 1px solid black”><div id=”progress_bar” style=”height: 24px; width: 1px;background: blue;”></div></div>’;
ob_flush(); flush(); usleep(300000); // <- forces output to be sent to browser

// tell the user we’re 10% done:
echo ‘<script>document.getElementById(“progress_bar”).style.width = ’10px’; </script>’;
ob_flush(); flush(); usleep(300000);

//…do some processing…//

sleep(3);

// tell the user we’re 50% done:
echo ‘<script>document.getElementById(“progress_bar”).style.width = ’50px’; </script>’;
ob_flush(); flush(); usleep(300000);

// tell the user we’re 100% done:
echo ‘<script>document.getElementById(“progress_bar”).style.width = ‘100px’;</script>’;
ob_flush(); flush(); usleep(300000);

?>
[/CODE]

Thanks much!

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@SrWebDeveloperDec 05.2009 — Look carefully at this proof of concept code:

[code=php]if (ob_get_level() == 0) ob_start();

for ($i = 0; $i<10; $i++){

echo "<br> Output stuff";
echo "$i..."; // Display your progress bar stuff here
echo str_pad('',4096)."n"; // Send bytes (spaces) of output to resolve flush issue

ob_flush();
flush();
sleep(2);
}

echo "Done.";
ob_end_flush();[/code]


Due to caching limitations you need to have at least 256 characters of output present for the flush command to do it's job. This code obviously ensures that, and is a known value that works well. For good measure I included the initial ob_start() at the top. As to the Flush issue that's described in depth here.

Just modify the above code using your own loop counter values, progress bar code and sleep wait time (or usleep as you used).

-jim
Copy linkTweet thisAlerts:
@theflyingminstauthorDec 05.2009 — Hey Jim, thanks so much for taking the time to explain this to me/send me the link!
×

Success!

Help @theflyingminst spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...