No indication that a web page is loading

268 views
Skip to first unread message

Georgi Lazarov

unread,
Mar 17, 2013, 11:12:38 AM3/17/13
to phpde...@googlegroups.com
Hi Czarek!

First I want to say a big thank you, as your php-desktop app is helping me a lot! It is a realy great solution for people who want to quickly build a powerful desktop app in php.

Currently I'm working on a project which uses a php scripts to calculate md5 of a video files and pack them in a tar/zip along with xml files created. Since that is a time consumtion process, it would be very useful to have an indication that a web page is loading while the script is running. If I run the same php code under regular browser, the indication of a running background process will be on a tab, but since your app don't have tabs...

Probably a possible solution on my side would be to create a progress bar in ajax, but I'm not sure how to accomplish that since I'm not so familiar with ajax.

I read issues you posted, and the Issue 15 looks to me like the issue I described here, but I'm not entirely sure ? If my problem is something different, maybe you want to add it as a new issue ?

Best regards,
Georgi

Czarek Tomczak

unread,
Mar 17, 2013, 1:13:36 PM3/17/13
to
Hi Georgi,

It sounds like a time consuming task, packing video file should definitely be done 
in background, in a separate thread so that it doesn't hang up the browser and also
so you can display a progress of this job. Yes, issue 15 [1] describes possible solutions
to your problem. Using ajax should be the simplest solution I think, you just load a 
"pack_video.php?job_id=1" script with the XMLHttpRequest object [2] so that it runs in background
in a separate thread, you can find many examples on the web, this script may insert a record to a
database table called "video_job" with the job_id=1, this table should have a column named 
"progress" that will be updated by the "pack_vide.php" script. Using ajax you can query this table
for the progress and display it to the user.

There is also possible an other solution that I have sometimes used, it doesn't require you to use
any ajax techniques. You need to disable output buffering, zlib compression or others in php settings,
so that when you echo a string it gets to the browser immediately, take a look at this example code:

ini_set('zlib.output_compression', 0);
ini_set
('output_buffering', 0);
ini_set
('implicit_flush', 1);

function fprint($s)
{
    $args
= func_get_args();
    call_user_func_array
('printf', $args);
    ob_flush
();
    flush
();
}

Now you can load the "pack_video.php" script in the browser, this script should output a string
that is a call to a javascript function that updates the progress bar using the "fprint" function:

<script>update_progress_bar(20%);</script>

Of course while this script executes user could click some link on the page and the php script
"pack_video.php" would be terminated, so it has its disadvantages compared to the ajax solution.

Cheers,
Czarek

Georgi Lazarov

unread,
Mar 17, 2013, 3:00:08 PM3/17/13
to phpde...@googlegroups.com
Thanks Czarek for the quick reply and helpful information!
Will have a look at your suggestions.

Br,
Georgi
Reply all
Reply to author
Forward
0 new messages