Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: (crazyinsomniac) Re: Detect Stop Button

by hakkr (Chaplain)
on Nov 26, 2001 at 19:58 UTC ( #127555=note: print w/replies, xml ) Need Help??


in reply to (crazyinsomniac) Re: Detect Stop Button
in thread Detect Stop Button

My script is writing a bunch of html files to disk created from Mysql searches. It only perfoms the searches and writes the files if it recieves all the form data.
Thanks anyway I'll try and be more detailed in future.
  • Comment on Re: (crazyinsomniac) Re: Detect Stop Button

Replies are listed 'Best First'.
Re(2, dmm): Detect Stop Button
by dmmiller2k (Chaplain) on Nov 26, 2001 at 20:41 UTC

    Perhaps another approach may work. Depending upon your application, you may want to provide a mechanism for the user to stop the process:

    In your script, create a session key (incorporating the process ID and perhaps hostname of the running script, for example) and store it in a cookie. Before the "meat" of the script begins ("...writing a bunch of html files to disk created from Mysql searches..."), write out some HTML containing a button or a link which when clicked, launches a second script which uses the value in the cookie to identify the first script's process and kills it.

    I realize this is not the solution you asked for. As you can see from the other responses, due to the asynchronous natture of HTTP discourse, there is no completely reliable way to detect browser disconnection.

    Pressing Stop itself is not even reliable: I've seen circumstances with Internet Explorer (v5.5 SP2) where clicking Stop (or hitting Esc) had no immediate effect -- the spinning globe just kept spinning. I haven't made a study of the prevailing conditions at the time, but invariably the browser was waiting for some object or another (i.e., image or ad) to load.

    Perhaps offering users an alternative to waiting might be attractive enough that they'll prefer it over simply browsing away from your results page. This approach won't prevent users from hitting Stop or browsing away from your page, but it might cut down the number of instances of it.

    dmm

      FYI, most instances I've seen of IE not stopping when you tell it to are JavaScript image loads. It's especially annoying on sloooooooow sites with lots of rollovers.
      --
      man with no legs, inc.
(joealba) 1 hour cgi script?
by joealba (Hermit) on Nov 27, 2001 at 19:14 UTC
    Reply from thread below: My script runs for about 1 hr so I had set my Apache TimeOut variable to a huge value (3600). This seems to work for most browsers. I think I'll try your idea of printing blank chars to STDOUT instead. The TimeOut variable effects all requests and probably leaves me with lots of Apache children hanging around

    Okay, so let me make sure I'm clear on this. You have a CGI script which runs for almost one hour. This cgi script creates a number of static html files to represent results from MySQL searches? Is the user expected to hang around for an hour to view the resulting html pages?

    It sounds like you *really* should be taking in the form information, verifying that you have all the form data, then writing this form data to a file. Then, a cron script should run every so often to see if any form data files exist, and process them accordingly. Then, the cron script could send the user an e-mail upon completion.

    By verifying your form data way before the script even runs, you will save those times where someone says "Oh shoot, I mistyped this field.. let me go back." You also can more appropriately schedule the running of this one hour script to not choke up your system.

    Besides, I can't think of ANY reason that a cgi script should run for longer than 5 minutes or so, and even that is quite silly. No one is going to watch the output for a whole hour, so you might as well e-mail them when it's done.
      I think you're making too many assumptions about the user. If it's an "in house" type of "admin tool", it could be some kind of reporting tool so that a manager doesn't have to know how to make MySQL queries. For example, maybe they only need the information on demand about every other month, so it would be wasteful to have a cron job doing an hour of processing every day. You might think just run a command, but some people don't have any idea what that really means, and developers get tired of being command-line (and MySQL :) monkeys.
        Well, cron jobs can run at any interval.. once a minute, once an hour, once a month... You just make the best choice for the application.

        There is still no good reason for a CGI script to run for 1 hour. Leaving a browser window tied up for that long is a Bad Idea, especially when a browser timeout will stop this lengthy report from running.

        The process could maybe be started through a CGI script, forked off, and then e-mail the user when it is complete. But, it shouldn't sit there running.

        TMTOWTDI, but a 1 hour CGI script is the wrong way.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://127555]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2022-08-19 07:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?