Time Intensive PHP Script & Client Progress Bar - How Would You Do it?

Associate
Joined
23 Oct 2002
Posts
1,525
Location
That London, née Brighton
Since making my original thread I've tried several ways of achieving my goal and can't get it to work, so I'm wondering what other methods you guys might suggest.

Assume a php process which takes 45+ seconds to run, maybe more.
We want to launch this process on the web server, from a browser, somehow.
We also want the browser to be updated with the progress of the process (it's scanning other sites so overall time will vary with each execution) so the client isn't left sat staring at an empty page and so the browser itself doesn't timeout.

How would you do it?

Things that don't work
1. I have permission to exec() but can't invoke php scripts via it, for some odd reason
2. Firing the request to start the scan via ajax, and then requesting the progress update(s) via ajax, doesn't work in internet exploder because it won't do anything else net related while it's waiting for the first (45+ seconds) script to return
 
It's this original fire and forget thing that the browsers just don't seem capable of forgetting. Or, well, iexplore doesn't anyway. I even tried issuing a header('Location:'); redirect in the initial scanner php, just before it starts scanning, and flush() and such, but the browser still waited 20 seconds before even doing anything with that. Very weird and annoying.
 
An iframe! An iframe which loads the scan script from a subdomain then the main window can still fire off the status updates! This may very well be a plan...
 
Ok it works in firefox. Here comes the big moment...

Nope iexplore still just waits for the iframe to load. Next stage then is try and make the iframe make an ajax request then the main window make an ajax request...
 
Last edited:
I guess then that by "initial request" you don't mean my initial request that causes the scan to take place? That request won't see a response for 40+ seconds. I'm considering this idea of trying to flush() some javascript after each iteration of the loop but I know apache tends to cache stuff anyway regardless of what php tries to do, so I'm not holding my breath ._.
 
Still getting buffered :(

I've modified my loop (which presently scans 112 pages) to send this after each page gets scanned

PHP:
print '<script type="text/javascript">parent.derp('.$i.');</script>';
flush();

which gets sent into the iframe. derp is a function in the parent which just alerts the variable passed.

Lo and behold, it does nothing for 40+ seconds then starts alerting numbers 1 through 112.

I'm tearing my hair out with this now ._.

P.S. using fiddler2 I can see it's not being gzip encoded, either
 
Last edited:
Still no dice :(

Also, now I look at it in Fiddler and t's saying it is gzip encoded. Seems I was mistaken last night. So trying to disable this now. Have tried:

1. using modified php.ini in my own directory (I know this gets read) with "zlib.output_compression = Off" in it
2. .htaccess in there with "SetEnv no-gzip dont-vary" and "RewriteRule . - [E=no-gzip:1]" in it
3. using the exact php you've pasted

and still gzipping :(
 
Last edited:
Ah yes, well, this was my original model, but trying to do exec(); with php scripts didn't work, and pcntl_fork isn't compiled in, so unless I keep bothering the host (vidahost, they're good at support usuall) about this, it looks like I may not get very far.
 
Nice idea with doing it incrementally... obviously makes it a bit flakier and such but, hrm, interesting idea...

Am also trying posting on vidahost's forums about the exec() issue, see if anyone else has resolved it, as if they have, it's all fine and sorted
 
Refactored it to be browser driven this morning, as you suggested Mr ArtificialFoxx, and it's now working sweetly. Thanks all :)
 
Back
Top Bottom