Is it possible that I would be able to spawn a detached daemon like process, from a CGI script
that stores read text files in memory, then re-access the memory in the next cgi execution, reading the data using a pipe?
Would most hosting ISP’s, allow detached processes? Are memory pipes fast, and easy to code/work with on a unix/linux system?
Is there a solution, that can be done without using any extra CPAN modules? This is a CGI process, so I want to keep it to a minimum.
Say you have a simple
resource.cgi:Its output is
The fun part is in
Reader.pm, which begins with familiar-looking boilerplate:Next it defined rendezvous points:
The sub
importis called as part ofuse Module. If the daemon is already running, then there’s nothing to do. Otherwise, we fork off the daemon and write its process ID to$PIDFILE.Every client needs to wait its turn getting a lock on
$PIDFILE. Once we have the lock, we then check that the process identified is still running and create the named pipe if necessary.Finally, reading the pipe is trivial:
Don’t forget to return a true value from the module:
You’ll note that operations can still fail in the daemon. For your sanity, you’ll want to log events somehow rather than choking silently.
As to whether hosts will permit long-running processes, that will vary from provider to provider, but even if your daemon is killed off from time to time, the code above will restart it on demand.