...

View Full Version : Print Please Wait Message While Generating Output



netroact
07-18-2009, 02:52 AM
I have an image manipulation script that takes awhile to generate the output. I want to print to browser a "Please Wait" message during the interim. I tried a print statement at the beginning of the script, but it just waits to display with the other output. I'm not gonna post the code. It's top secret. :D
Could someone help me please?

bazz
07-18-2009, 02:59 AM
I seem to recall that this would require a forked process. It enables a propcess to split into two such that one can be the temp message and the other the actually process you already wrote. when the main process has been completed, then it changes the output message.

I had a need for it once but couldn't get my head around it. so I am not much help really :(

you might find this link helpful but search under 'forking problem'

http://www.codingforums.com/showthread.php?t=103926&highlight=forking+problem
bazz

Shannon Blonk
07-18-2009, 03:52 AM
Two possible sources of the delay:

1. Perl buffering output. In plain CGI stuff, you can use

$|=1;

to enable auto-flushing on the active output handle. For more complicated object oriented stuff, check the doc's for an autoflush method or for inheritance from IO::Handle.

2. Browser don't always render immediately, specially with partial content and unclosed tags. Try wrapping your message in <pre> tags (preformatted means easy to render) or follow it with a <br> or <hr>.

netroact
07-18-2009, 04:31 AM
I seem to recall that this would require a forked process. It enables a propcess to split into two such that one can be the temp message and the other the actually process you already wrote. when the main process has been completed, then it changes the output message.

I had a need for it once but couldn't get my head around it. so I am not much help really :(

you might find this link helpful but search under 'forking problem'

http://www.codingforums.com/showthread.php?t=103926&highlight=forking+problem
bazz

Thanks for the reply. There might be an answer in that thread, but I'm not smart enough to figure it out.

netroact
07-18-2009, 04:45 AM
Two possible sources of the delay:

1. Perl buffering output. In plain CGI stuff, you can use

$|=1;

to enable auto-flushing on the active output handle. For more complicated object oriented stuff, check the doc's for an autoflush method or for inheritance from IO::Handle.


Not sure what you are talking about here, but thanks for the reply.



2. Browser don't always render immediately, specially with partial content and unclosed tags. Try wrapping your message in <pre> tags (preformatted means easy to render) or follow it with a <br> or <hr>.

I have a third party script that prints a please wait message, and then lists the environment variables underneath it. It uses tables and br tags. I tried that formatting, but it didn't work in my script.
I have since realized that's not what I want anyway. At present the script continues to display the form page until it's ready to display the output. I need the script to immediately display the please wait message until the output is generated, and then display the output on a separate page.
Appreciate any suggestions.

netroact
07-18-2009, 07:53 PM
I have been searching through the back alleys, and other hidden places. Finally came up with this:

http://www.stonehenge.com/merlyn/WebTechniques/col20.html

I think I might be able to figure it out over the next few years, but if anyone can adapt it sooner, I would be extremely grateful.

Shannon Blonk
07-18-2009, 08:27 PM
Let's start with more details: how long does your image manipulation script require? what sort of output do you want? fancy javascripted paged or pure html or just the images itself?

netroact
07-18-2009, 08:49 PM
I start with a form page. The user clicks the submit button. I need it to immediately display the message, "Please Wait", so that the user doesn't think the program has hung. Depending upon the form data, the script will run from 2 seconds to 2 minutes.
I don't need help with the html or the image script. I just need help with running both processes at the same time. The url I referenced above shows how to do this with a search script. I need to adapt it to my script.
Thanks!

Shannon Blonk
07-19-2009, 08:57 PM
Well, let's arbitrarily say you're okay with mandatory javascript (light-weight), and running stateless cgi on some *nix variant...

I'd have a daemon that reads from a named pipe (blocking when there's nothing to read, of course). cgi gets a request, writes a message to the named pipe. Daemon unblocks/reads message, forks off the manipulation script which sets to work. Meanwhile, the cgi sends a page back to the browser with a 'working...' message and an image, then exits. The image (which doesn't yet exist) has an onerror handler that animates the working messages and then re-requests the image.

Eventually, the manipulation script finishes and is reaped by the daemon. Once the image exists and is successfully loaded, an onload handler clears the working message and generally tidies up.

named pipes, daemons, and reaping (http://search.cpan.org/perldoc?perlipc)

netroact
07-19-2009, 09:32 PM
I kinda sorta follow everything you said in that post except this:

Eventually, the manipulation script finishes and is reaped by the daemon.

I no longer have any problems with javascript, since most everyone is using it on the Web now. If you would be willing to provide some example code, I'm sure many people on the Web would appreciate it, since I can't find any specific examples of this anywhere. There are many posts, but very hazy answers.

RabidMango
07-20-2009, 11:27 AM
That's pretty sophisticated Shannon. When I am a billionaire I may have to rent your brain for my perl department.

Can I suggest to the querant this other route to solving the problem, much less sophisticated:

Use a (javascript) onclick call in the submit button (for the form you are talking about) which makes a little popup window appear (named) in the middle of the screen at the same time that the form is sent for processing, with a nice graphic saying "please wait..." blah blah - with some nice animation to indicate time passing.

Then on the output of your cgi have an onload function which closes that popup.

Presto-hey, job done, problem solved. That will work 100% fine will it not, Shannon, and requires absolutely no tricky sophisticated were-you-born-inside-a-unix-server perl?

netroact
07-20-2009, 10:57 PM
Use a (javascript) onclick call in the submit button (for the form you are talking about) which makes a little popup window appear (named) in the middle of the screen at the same time that the form is sent for processing, with a nice graphic saying "please wait..." blah blah - with some nice animation to indicate time passing.

Then on the output of your cgi have an onload function which closes that popup.

Presto-hey, job done, problem solved. That will work 100% fine will it not, Shannon, and requires absolutely no tricky sophisticated were-you-born-inside-a-unix-server perl?

I had thought about popping up a prompt on exit, but it would require another click to close the prompt. Never thought about popping up a window with a javascript hyperlink. Not sure how to close the window at the script output though. It wouldn't be a self-close would it? Gonna have to polish up on my javascript.

Thanks for the reply.

RabidMango
07-20-2009, 11:01 PM
Javascript window.open, also fullscreen and centered popup window ...
<a href="javascript: void(0)" onclick="window.open('popup.html', 'windowname1', 'width=200, height=77'); return false;">Click here for simple popup ...
javascript-array.com/scripts/window_open/ - Cached - Similar

(I just snipped that right off a google search, as you can see)

This page seems to have the appropriate facts relating to closing the window again:
http://www.javascript-coder.com/window-popup/javascript-window-close.phtml

Since the window is given a name, then on the new page that loads you can just put some javascript in closing the window which has that name the moment the page has loaded.

netroact
07-20-2009, 11:07 PM
Thanks! I'll look into that.

Shannon Blonk
07-21-2009, 12:10 AM
Grrr. Simple solutions! :( How can you expect to be promoted to upper-middle project management without a dozen inter-dependent processess in at least four layers? :p

Yeah, ignore what I suggested earlier... I've been to too many meetings this week -- it's making my brain enterprisey.

netroact
07-21-2009, 01:27 AM
The javascript won't work. Most people have popup blockers.

RabidMango
07-21-2009, 01:34 AM
Wow, talk about spammers ruining our industry.

It's true. Firefox comes with it as a default setting.

Luckily there's an answer -

with javascript you CAN write to the page - just print straight onto the page, i.e. set the value of the content on any part of the page you want.

So your onsubmit can get the javascript to write a new image tag to some appropriate part of the page and then there's no need for any second part. The middle of the page just shows an animated gif.

Here's the instruction manual:
http://www.mediacollege.com/internet/javascript/basic/document-write.html

netroact
07-21-2009, 02:40 AM
Hey! You can't do that. You can't thank the orignal poster. The poster's spose to thank the best answerer.

netroact
07-21-2009, 02:41 AM
Wow, talk about spammers ruining our industry.

It's true. Firefox comes with it as a default setting.

Luckily there's an answer -

with javascript you CAN write to the page - just print straight onto the page, i.e. set the value of the content on any part of the page you want.

So your onsubmit can get the javascript to write a new image tag to some appropriate part of the page and then there's no need for any second part. The middle of the page just shows an animated gif.

Here's the instruction manual:
http://www.mediacollege.com/internet/javascript/basic/document-write.html
Thanky! I'll play around with that idea.

bazz
07-21-2009, 12:46 PM
Hey! You can't do that. You can't thank the orignal poster. The poster's spose to thank the best answerer.


heh, but you gave an answer to their question, before they had asked the question. :)

sentweb
11-27-2010, 07:00 PM
I know this is an old post and this may not work if your code causes a delay pointing to the redirected/confirmation page. If I have a slow loading page, I setup a background image in the body statement. background="../images/background.gif" I just make a simple gif image such as 800x250 with the color I need and put the text message in the image. Most browsers (IE,FF,CHR) will load the background image before other page info, and will see the message from the gif. When the page loads, it covers up the background image. You may need to make a 100% table cell to put your page contents in so it hides the background once loaded on some display settings. Yes, the message could repeat on higher display settings, but not too much if you put the message on the lower right of the pic.

netroact
11-27-2010, 10:12 PM
I'll try that, but I don't see how it works.

netroact
12-16-2010, 11:35 AM
Well, Ok, but I'm not quite sure how to implement that into my code. It would probably look better though. :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum