Question

Create "please wait" page while process running

Asked by: td234

I know there have been similar questions asked but I have yet to find a solution to fit my needs. Any suggestions will be appreciated.

I have a PHP page that sends emails to a newsletter list. It takes a while and my browser (Safari) timesout after 60 seconds. The script has "set_time_limit". The script is not timing out, the browser is timing out.

My current attempt at solving this is to open a pop-up window (onSubmit) that has an animation that says "please wait while we send the messages". The opener window is sending the emails and if it completes the task will close the pop-up window (onLoad). This works unless the opener window takes more than 60 seconds and it give an error that it has tried to open the page for 60 seconds and has quit trying.

I also tried putting a PRINT line in the script above thinking if it kept sending text to the original window the browser would be satisfied that the page was still coming, but that does not seem to work.

I believe it is still possible to send a header that will allow ou to stream text to a browser so I could create the page that says "please wait" and print a (".") period every 10 emails. I have nto been able to find out how to do this. Anyone know? I think this would solve my problem and even negate my need for the pop-up window.

Anyone have any other solutions to a situation like this? Most the travel sites do this while looking up your reservation. Any idea how they do it?

Thanks for any suggestions.

Thom

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2004-05-19 at 14:02:09ID20995381
Tags

php

,

wait

,

please

,

page

Topic

PHP Scripting Language

Participating Experts
5
Points
500
Comments
18

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. onsubmit
    This que is not related to front page. I am here because HTML ask a que is not running currently. I cant get a function call on onsubmit. In the form tag I have action="blabla.asp" onsubmit=heck_data(this) My problem is I cant get to call the function What am I d...
  2. onblur event not suppotred in safari browser
    The onblur event in the body tag is not supported in the safari browser According to W3C onblur is not a valid attribute of the <body> tag. I have a form with a file upload button and when the submit button is click a 'please wait' new window opens from an external j...
  3. SoftArtisan - Upload Failure with Safari - A bit urgent
    I'm using SoftArtisan's FileUp (Version 4.01, I think),VBScript, Javascript, Ajax, and an animated GIF. I'm trying to upload a file from a form using Safari. All of the form elements come through fine except the one for the file name. I dumbed down the code to just save the ...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: CrYpTiC_MauleRPosted on 2004-05-19 at 15:01:07ID: 11112431

header('Refresh: 5; URL=/emails.php?sent=whateveramount');

This way you can output text like so...


Processing....

and after 5 seconds the page will redirect and timeout or output

Processing next batch of emails..... etc

then after 5 secs page refreshs to next.

 

by: td234Posted on 2004-05-19 at 16:01:57ID: 11112748

I had thought of refreshing the page, but I have many variables which are passed as _POST vars including full text and html versions of the message which could get quite lengthy for the subsequent _GET post you suggest above. What is the limit for a QUERY_STRING?

 

by: ThGPosted on 2004-05-19 at 16:17:11ID: 11112798

you mean max url size? i think 1024, but i'm not 100% sure.

You mailing system is quite poor, you cannot rely on browser's request for such activity, because any interruption of the request (browser timeout, network problems, and so on) would stop the process.
I would rather use a crontab entry that triggers a php script (using the CLI php binary) that every 5 minutes polls file X for its existence. If it exists, opens it for reading and fetches your POST variables previously saved and then starts sending mail. In this case there is no time limit.

 

by: td234Posted on 2004-05-20 at 08:28:16ID: 11118196

Thanks CrYpTiC_MauleR

I think you are on the right track. I have rebuilt me page to process 100 at a time and then I use header(Location: ...) to process the next group. This works well and as I need. I was looking at your suggestion above with the Refresh which would let me print to that window in addition to reloading it. I would like to do that, but am concerned that if it takes more than 5 seconds to process a batch, then the page will be refreshed calling the next group and the tail of the previous group will get cut off.

Does this make sense? If I use "ignore_user_abort" will the previous batch continue even after the reload in 5 seconds?

 

by: ASCII_ManPosted on 2004-05-21 at 00:25:42ID: 11124470

Keep in mind an error on the client would cause screwups in the sending, i.e. the browser crashes (for whatever reason) and messages have are sent out to indivduals twice or more.

IF you plan to go ahead with the process-100-per-page plan, I recommend you put in handling for the event the client computer starts a mail batch, but never completes it - allow them to resume from the last point in the batch.

Otherwise, for the easier option of just doing it all in one go it should be quite easy to send a period every 10 messages.

Simple example:
[code]
ignore_user_abort(true); // keep processing even if the client goes away
echo "started mail batch, each "." means 10 messages have been sent<br />";
$sql = "select user_email, user_firstname, user_lastname FROM user_table WHERE user_in_mailinglist = 1";
$query = mysql_query($sql) or die("mysql error: ".mysql_errnum().":- ".mysql_error()."<br />".$sql);
$rows = mysql_fetch_array($query);
for($loopy = 0; $loopy < count($rows); $loopy++){
   /*
    * Mail stuff here
    * mail($rows[$loopy][0], $email_subject, $email_body);
    */
   if(($loopy %10) === 0)
      echo ".";
}
if(connection_aborted()){

}
echo "mail batch complete!<br />";
[/code]

 

by: ASCII_ManPosted on 2004-05-21 at 00:34:39ID: 11124485

... damn tab button... damn space bar. Damn inability to use a computer.

I didn't quite finish that:

[code]
ignore_user_abort(true); // keep processing even if the client goes away
/*
 * Make a log that the mail batch began
 * $sql = "INSERT INTO mail_batches VALUES ( DATE(), 'Begun processing the batch (started by '.$_SERVER['REMOTE_ADDR'].')')";
 * query($sql);
 */
echo "started mail batch, each "." means 10 messages have been sent<br />";
$sql = "select user_email, user_firstname, user_lastname FROM user_table WHERE user_in_mailinglist = 1";
$query = mysql_query($sql) or die("mysql error: ".mysql_errnum().":- ".mysql_error()."<br />".$sql);
$rows = mysql_fetch_array($query);
for($loopy = 0; $loopy < count($rows); $loopy++){
   /*
    * Mail stuff here
    * mail($rows[$loopy][0], $email_subject, $email_body);
    */
   if(($loopy %10) === 0){
      echo ".";
   }
   if(connection_aborted()){
      /*
       * Make a log that the mail batch completed
       * $sql = "INSERT INTO mail_batches VALUES ( DATE(), $_SERVER['REMOTE_ADDR'].' stopped watching the batch process')";
       * mysql_query($sql);
       */
   }


}
/*
 * Make a log that the mail batch completed
 * $sql = "INSERT INTO mail_batches VALUES ( DATE(), 'Completed processing the batch (started by '.$_SERVER['REMOTE_ADDR'].')')";
 * mysql_query($sql);
 */
echo "mail batch complete!<br />";
[/code]

 

by: rlawleyPosted on 2004-05-21 at 08:38:22ID: 11127731

The solution above seems fine as long as you can ensure that you have control over the php script timeout - if you don't and it's set to a low value then it will still quit.  I've done something remotely similar which I've used to avoid a script timeout on a photo website for resizing images.  You need to write the page so that each time through the script it can get a list of e-mail addresses still due to be sent - easiest way would be to store all the data for sending the messages in the session, with the destination addresses in a queue or similar.

Next thing is to set the META refresh tag to reload the page after the same time as your script timeout.  This should mean that it works on simple browsers.

In your php script, you need to record the time the script started running, and the number of messages processed so far in this execution.  At the start of each time through the loop, use this information to predict whether the timeout will occur this time round.  If it does, don't execute and echo a javascript command to refresh the page.  Then stop processing and wait.  If the browser supports Javascript it will immediately refresh and carry on.  If JavaScript is disabled, the meta tag should cause the page to be refreshed.

If you are interested in this approach, I can dig out sample code.  I find it very effective for running long repeated jobs on machines where the script timeout is set too low.  It should also get around your problem of the browser timing out, and you can add progress information to the page each time it is reloaded if you wish.

 

by: AlanJDMPosted on 2004-05-21 at 13:53:24ID: 11130185

I do this a slightly different way than what has been discussed thus far. I use the exec() function to launch a seperate script in background...

exec("php script.php &");

At the end of that script I set a flag in a table that indicate it is done running. That way all my "please wait" page does is refresh every 10 seconds checking that flag. This way there is no timing issues and worrying about refreshing before it is safe to do so.


Alan

 

by: td234Posted on 2004-05-21 at 14:09:19ID: 11130291

I thought I had a great solution with the header(Location) to the script calling the next 100 addresses, but ran into this problem. If I had too many addresses, my browser gave me a message that there were too many redirects and it was giving up. Bummer.

I suspect using header(Redirect: 5; Location...) would do the same.

I hate to take this alternative, but I might be forced to create a file and have a cron job run every few minutes.

Suggestions?

 

by: ThGPosted on 2004-05-21 at 16:58:12ID: 11131056

> I hate to take this alternative, but I might be forced to create a file and have a cron job run every few minutes.

It's NOT a bad alternative..it's a GOOD alternative.

You may also try to spawn a background process yourself.. not tested, but the idea should work:

system("/usr/bin/php -f /path/to/your/mailingscript.php &");
echo "Mailing launched in background";

that final "&" should allow your http request to complete immediately and let the mailing script work in background.

 

by: AlanJDMPosted on 2004-05-24 at 04:32:22ID: 11141985

"You may also try to spawn a background process yourself.. "

Hmmmmm, this sounds familiar. I wonder where I heard this before?

Alan

 

by: ThGPosted on 2004-05-24 at 09:53:51ID: 11144654

> Hmmmmm, this sounds familiar. I wonder where I heard this before?

You are right AlanJDM, I didn't notice your post, i'm sorry. Please ignore my previous comment.

 

by: rlawleyPosted on 2004-05-24 at 10:57:48ID: 11145214

I agree that the spawning technique would appear to be the best.  I wrote mine to get around safe mode on a webserver, where there is no chance I can spawn external processes.  If you can use something in the background, it would be much better.

 

by: td234Posted on 2004-05-24 at 13:30:26ID: 11146426

Hey AlanDJM, Can you explain how you do this...

>At the end of that script I set a flag in a table that indicate it is done running. That way all my "please wait" page does >is refresh every 10 seconds checking that flag. This way there is no timing issues and worrying about refreshing before >it is safe to do so.

How does a newly refreshed page check to see if a speerate process is completed?

Thom

 

by: AlanJDMPosted on 2004-05-24 at 13:46:42ID: 11146543

The script that runs in background will update a field in a table to a value, I would use 1 and 0. At the beggining of the script it would set this value to 1 which will indicate that the script is running, and at the end of the script it will change the value to 0 which indicates it is not running.

Then, the page that gets refreshed will contain a script that queries that value. It will continue to refresh until it sees a 0. When it sees a 0 it will know the script is done running and react accordingly, probably with a header call back to the original page with a message that says "complete".


Alan

 

by: td234Posted on 2004-05-24 at 13:57:32ID: 11146627

Alan, nice idea. I guess the only problem could be too many redirects (from waiting too long) causing the borwser to stop trying to load the page like I got when I tried to reload every 10 emails.

 

by: AlanJDMPosted on 2004-05-24 at 14:04:35ID: 11146679

No, there is only one redirect... the end of the script. The only script that will run a long time is the script in background. The script that is refreshing will only redirect once, after the flag gets set. There is nothing to timeout.


Alan

 

by: td234Posted on 2004-05-24 at 14:26:48ID: 11146822

Sorry, I meant to many refreshes, but my problem with the browser was too many redirects and refreshes might not cause the same problem. Let me give it a try.

T

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...