Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Will script terminate with window closing

by htmanning (Friar)
on Apr 19, 2014 at 04:28 UTC ( [id://1082857]=perlquestion: print w/replies, xml ) Need Help??

htmanning has asked for the wisdom of the Perl Monks concerning the following question:

Monks, I have a database of 100 email addresses. I wrote a script that will present a form to be filled out. When the form is submitted, the contents get emailed to all email addresses through a while routine. My question is if I present a "success" HTML page after the form is submitted, will the script continue to run and complete the sending of all emails if the user closes the browser window or clicks to another page? If I make them wait until the emails are sent it could take a long time so I'd rather just present the success page. Thanks.
  • Comment on Will script terminate with window closing

Replies are listed 'Best First'.
Re: Will script terminate with window closing
by GrandFather (Saint) on Apr 19, 2014 at 05:15 UTC

    Think about the nature of the communication between the server computer running your script and your user's browser running on a computer which may be on a different continent across the far side of the world from your server. In particular, how is the user closing the browser window they are using going to affect the script running on a different machine. The internet uses a fair degree of magic to get its job done, but with a little thinking and investigation you can generally at least appreciate the nature of the magic and its limitations.

    Perl is the programming world's equivalent of English
Re: Will script terminate with window closing
by NetWallah (Canon) on Apr 19, 2014 at 05:39 UTC
Re: Will script terminate with window closing
by sundialsvc4 (Abbot) on Apr 20, 2014 at 01:35 UTC

    Personally, I suggest that a CGI script should not carry out long-running activities such as “sending 100 emails.”   To my way of thinking, “a web-page is a user inteface; nothing more.”   If you have something that takes a long time to do, I suggest that you set up some kind of persistent daemon process that is responsible for doing it, and have it (say) listen on a pipe for some instruction ... coming from the web site or what-have-you ... that tells it to start doing it.   All that the web-page needs to do is to confirm to the user that the request has been successfully posted (to the daemon).

    The entire notion behind the HTML protocol is that you “submit a request, get a response, then fuhgeddaboudit.” ...
    Request => Response ... Finis.
    ... and, so, that is precisely how I would structure the process that enables the user to request that 100 emails should be sent “real soon now.”   Don’t make him wait for it.   Heck, don’t allow him to wait for it.   That’s not what HTML is for.

      ... the HTML protocol...

      You meant the Hypertext Transfer Protocol (HTTP)?

      Thanks so much for this response. You're right. I need to figure out a different way to do it.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1082857]
Approved by vinoth.ree
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-20 03:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found