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

Hello,

I am attempting to create a system where there is one parent process that contains a hash of Net::SSH::Perl connections. This parent process listens to a UNIX Domain socket and when a connection is detected, fork()s off a child process to handle the requests of this child.

To keep it simple, let's say that each child process just wants to connect to the server and issue a "ls" through the existing Net::SSH::Perl connection. If a connection to the desired host doesn't already exist in the hash of already-authenticated connections, the child will attempt to connect. If successful, it issues the "ls". The catch is, I want to store this new Net::SSH::Perl connection in my global hash so that other children will have access to it.

Cache::Cache modules will not work, as the Net::SSH::Perl contain CODE refs and Storable doesn't handle these.

I've considered mod_perl, but that will only give me persistence of the Net::SSH::Perl cached connections on a per-httpd-process level, not a global level. (A user could theoretically hit two different processes and cause two Net::SSH::Perl connections to be created/maintained/cached).

Anyone have a suggestion regarding this? Even possible?

thanks.

(O|||||O)
  • Comment on Variable persistence between processes?

Replies are listed 'Best First'.
Re: Variable persistence between processes?
by dree (Monsignor) on May 23, 2002 at 19:55 UTC
    You could use PPerl : Persistent Perl.

    From the docs I read:

    This program turns ordinary perl scripts into long running daemons, making subsequent executions extremely fast. It forks several processes for each script, allowing many proceses to call the script at once.
      I also read (from its perldoc page):
      WARNINGS Like other persistent environments, this one has problems with things like BEGIN blocks, global variables, etc.
      I assume they mean the global variables become global on a per-process instance (such as mod_perl - ugh)...

      (O|||||O)
Re: Variable persistence between processes?
by Joost (Canon) on May 24, 2002 at 16:20 UTC
    Maybe you should take a look at IPC::ShareLite

    From the README:

    IPC::ShareLite provides a simple interface to shared memory, allowin +g data to be efficiently communicated between processes. Your operati +ng system must support SysV IPC (shared memory and semaphores) in order + to use this module.

    I assume you have SysV IPC, since you also have Unix domain sockets.

    Another candidate might be Mmap:

    README:

    The Mmap module lets you use mmap to map in a file as a perl variable rather than reading the file into dynamically allocated memory. It depends on your operating system supporting UNIX or POSIX.1b mmap, of course.
    -- Joost downtime n. The period during which a system is error-free and immune from user input.
Re: Variable persistence between processes?
by cybear (Monk) on May 24, 2002 at 16:59 UTC
    A humble offering from a fledgling coder...

    Could you not write your hash to a file?