Welcome to WebmasterWorld Guest from 54.85.162.213

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Handling high script execution times

How to keep the visitor informed of progress?

     
3:28 pm on Sep 4, 2008 (gmt 0)

Preferred Member

10+ Year Member Top Contributors Of The Month

joined:Mar 12, 2004
posts:514
votes: 25


I'm building a web based front end to an .exe program using PHP on a Windows server. Currently the visitor posts a form with a few variables to a php page which uses shell_exec to run the .exe.

Problem is the .exe file takes about 30 seconds to run, and has to run before the php page loads, so the visitor is left looking at the form submit page with no real feedback.

What would be the normal way of providing user feedback in this situation? Ideally I'd like to be able time the script and tell the user how long they had left to wait using a nice moving bar. Otherwise I guess some generic "page loading" image started on form submit.

What does everyone else do in this situation?

4:21 pm on Sept 4, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 24, 2005
posts:697
votes: 0


Yea i would simply echo a nice looking "Processing your data.." image and then call the exe, or you could use simple css progress meter if you don't want to use an image.
4:38 pm on Sept 4, 2008 (gmt 0)

Preferred Member

10+ Year Member Top Contributors Of The Month

joined:Mar 12, 2004
posts:514
votes: 25


There is my confusion - I can't echo anything from the page with the form because that's already loaded and I can't echo anything from the page with the shell_exec because that won't do anything until it's finished executing.

Are you thinking javascript or is there a cunning intermediate step I can take and use php? I'm very rusty on web and php and was never that good to start with.

8:19 pm on Sept 4, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 24, 2005
posts:697
votes: 0


Although there can be many other and better ways too, (if i am well rested ;) ) but as a starter idea what you can do is you use an IFRAME on your Form Processing Page, put your "Processing..." Message on a file in one frame and your main file that does shell_exec, call that in the other frame.
1:09 am on Sept 5, 2008 (gmt 0)

Junior Member

10+ Year Member

joined:June 6, 2005
posts:109
votes: 0


Have a look at flush() & ob_flush(). You can echo something, flush it and it'll get sent to the browser while the rest of the script is still loading. You might need to play with your html markup & pad the echoed string with whitespace to get it working, sometimes tables and things won't display in browsers until the whole table or a sepcificed number of characters has been received.
4:33 am on Sept 5, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 27, 2003
posts:751
votes: 1


Like MattAU says, try to output the whole page and flush it if you need to. Make the execute call toward the bottom of your script. Have the page display some loading graphic. Then after the execute completes, use a little javascript to forward the page to a "okay done" page.

I've never done something like that, but that's what I would try.

9:46 am on Sept 5, 2008 (gmt 0)

Preferred Member

10+ Year Member Top Contributors Of The Month

joined:Mar 12, 2004
posts:514
votes: 25


Thanks for those ideas - I'd not heard of flush(). It brought me right up against another issue - I don't really want to allow people to be able to refresh the exec() page as that would run the program again.

I've got a workaround with a bit of javascript. Browser requests the page with the form and it checks if they have javascript installed (maybe I'll show an alternative page if not).

Form OnSubmit calls a javascript function that un-hides a div with the loading graphic. Hopefully I can get some indication of time in there, though I have a suspicion javascript will stop working after I've navigated away from the page.

Form is posted to php page with shell_exec(), but the previous page with the loading graphic still shows until the program has executed. Right after the shell exec I've got a header redirect to a results page with an ID in the address so I know which results to show.

Beauty of this is a back button from the results page takes the visitor back to the form page, missing out the executable, but it might be less user-friendly for those without javascript.

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members