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

Hi, I am doing a web-based viewer to read messages sent from a daemon on separate server.
I have a listener script that opens a socket, repeatedly waits for messages to come in and then write to a log file.
I have also a viewer script that reads from the log file and displays the messages on the browser.

I want to allow the user to control the uptime of the listener script. My current idea is to let the user make a cgi request to start the listener script, get the pid and put into a file. When the user make a request to stop listening, the cgi script will read from the file and kill the listener process using the pid.
I intend to try this next Monday but I'm not even sure the cgi script is allowed to kill a process this way.

Can anyone with experience give me some advice or a better approach to doing this?

Currently,the user has to make a request to check for updated logged messages. Is that a way to have the viewer script auto-update the web-page whenever the log file is updated by the listener script? If so, the viewer script also needs to know when the viewer closes the browser window so that it will exit itself right?

  • Comment on Starting and stopping a listener script from CGI

Replies are listed 'Best First'.
Re: Starting and stopping a listener script from CGI
by merlyn (Sage) on May 05, 2001 at 21:56 UTC
    If you have control over the protocol being sent to the listener script, I'd suggest making it HTTP.

    Then you can use any of my column code that uses CGI.pm, HTTP::Daemon and fork as a model, and make yourself a "mini web server" as your daemon. Data is sent to the server by invoking a URL like a form. The server can be shut down by invoking a different URL. It' s all a small matter of programming.

    Google for "site:stonehenge CGI HTTP::Daemon fork" to find the unique hits. (Looks like WT columns 23, 24, and 56).

    -- Randal L. Schwartz, Perl hacker