1

Whenever I try to run a long operation with php it prevent the page from loading the other data before it completes the operation. (I know as php is serverside execution it does likewise).

But how can I use a progress bar to solve this issue so that the page will load and then shows a progress where the javascript call will initiate a php page to compile and show its result in the front

I here does a conversion process of video hence its sure the time depends on the file size it converts and so I really need to show the progress bar on the page where it navigate to.

3
  • 1
    by searching "php progress bar" on google? Dec 18, 2010 at 7:42
  • What kind of progressbar do you want? Do you want to show the 'progress' in it? Dec 18, 2010 at 8:04
  • yes I need to show the progress in that also
    – Rahul TS
    Dec 18, 2010 at 8:20

2 Answers 2

1

There are a few ways to approach this problem.

First, it really depends on whether you can get progress information from whatever process you are using to convert your video. If not, I recommend simply using some estimation for the progress in the front-end - ie, set up a timer in JavaScript and have it progress without actually talking to the back-end.

If you can get progress information, there are two main front-end to back-end ways you can handle this.

Firstly, you can use plain old HTTP and HTML in a synchronous process. You can call flush to write all your output to the client. You can set up a HTML page, call flush to write it to the client, and then periodically add new HTML elements (or JavaScript function calls) which you flush out to the client. In other words, add something like:

<div class="progressbar" width="77px"></div>

The CSS class progressbar will set the co-ordinates of the element and set the background colour, and the width (ever-increasing) will cause this to cover more space over time.

The JavaScript way is probably easier in some ways:

<script>
updateProgress(77);
</script>

You just need to create the function in the front-end that updates the actual progress bar.

A better way to do this is asynchronously. Instead of having the work happen in the PHP process that comes with a PHP request, use a job server (I recommend Gearman) or a queue (Amazon SQS or RabbitMQ are good options) to have this work be done in another process. That process can send its progress information to the job server, or to a database.

The front-end will use either a refreshing HTML page, or something with AJAX, to query the completeness of the job by some sort of identifier. The back-end which receives the query will check the job server or the database with that identifier to see how far along it is.

0
0

Please refer these link

http://sourceforge.net/projects/perlphpuploader/

http://webscripts.softpedia.com/script/PHP-Clases/PHP-Progressbar-25825.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.