John Saylor wrote:
> I am writing a mod_perl handler that takes a HTTP POST and sends mail. What
> I'd like to do is to open up a connection to the SMTP server [a Net::SMTP
> object] and a log file [filehandle] that exist outside of the handler. So
> that when the handler is run, it has access to these items, and can send
> data to them, but that they don't get opened up and brought down each time.
> 
> Right now, I have them being set up [and torn down] in BEGIN {} and END {}
> blocks. The code doesn't complain, and it sends the right thing back to the
> browser, but nothing gets mailed or written to the log.

Are you maybe opening filehandles and sockets in the parent process
before forking?  If you pull in the modules with the BEGIN code in your
startup.pl or httpd.conf, that would be the case.  You should move these
to a PerlChildInitHandler instead.

> My question is this: how do you set up persistent connections that a handler
> can use, but ones that don't get initalized each time the handler is called?
> 
> Are these just file [package] scoped globals?

Yes.  You can make an OO interface around them though, if you prefer. 
See the Class::Singleton module for an example.

> Do I need subroutines to check the status of these objects/handles and
> reinitialize them as needed?

It would certainly make yur code more robust if you checked the status
of your open sockets and filehandles before handing them off.

- Perrin

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to