Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Odd effects of mod_perl on IO::Socket or LWP::Protocol?

by ehdonhon (Curate)
on Aug 28, 2003 at 04:34 UTC ( #287237=perlquestion: print w/ replies, xml ) Need Help??
ehdonhon has asked for the wisdom of the Perl Monks concerning the following question:

Greetings monks. After several hours, this one really has me baffled. That is to say, I'll find the answer about three minutes after posting the question. :)

My issue is that I've got a piece of code that behaves differently depending on wether I'm running it from a script on the command line, or wether I'm running it from a cgi on a mod_perl server. My problem is getting LWP::UserAgent to talk to a particular site. I've traced the issue down in the code as far as this particular line:

my $ua = LWP::Protocol::https::Socket->new( PeerAddr => 'somewhere.example.com', PeerPort => 443, Proto => 'tcp', Timeout => 180, KeepAlive => '', SendTE => 1 );

Whenever I run this from a CGI, I find that $ua contains undef. I also find that $! contains 'No such file or directory'.

However, whenever I run this from a script off the command line (running as the webserver user, so it isn't a permissions issue), it works fine!

My first question is: does anybody know of any weird interactions with perhaps either Net::HTTP or IO::Socket::INET that might make it behave differently depending on which modules are already loaded, or depending on the presence of mod_perl?

My second question: how can I trace exactly where that 'No such file or directory' is coming from? I have a feeling if I can drill down to wherever that error is being generated, I'll find my problem. However, there just doesn't seem to be a real good way to trace it!

Comment on Odd effects of mod_perl on IO::Socket or LWP::Protocol?
Download Code
Re: Odd effects of mod_perl on IO::Socket or LWP::Protocol?
by Zaxo (Archbishop) on Aug 28, 2003 at 04:48 UTC

    Check to see if the server is looking for /usr/bin/perl^M. That happens when scripts written on winders are uploaded as binaries.

    After Compline,
    Zaxo

Re: Odd effects of mod_perl on IO::Socket or LWP::Protocol?
by perrin (Chancellor) on Aug 28, 2003 at 04:53 UTC
    Is it running under CGI or under mod_perl? The simplest way to trace errors is to comment things out until they stop happening. A possibly better way is to use the debugger, which you can do under mod_perl. Check the docs for information on how to do it.
Re: Odd effects of mod_perl on IO::Socket or LWP::Protocol?
by dws (Chancellor) on Aug 28, 2003 at 05:50 UTC
    Whenever I run this from a CGI, I find that $ua contains undef. I also find that $! contains 'No such file or directory'.

    Take a look at $@. It might be getting set from Net::HTTPS while trying to find an SSL implementation. There might be a protection issue on one of the files.

Re: Odd effects of mod_perl on IO::Socket or LWP::Protocol?
by mattriff (Chaplain) on Aug 28, 2003 at 12:23 UTC
    One possibility: the module Net::HTTPS, used by LWP::Protocol::https::Socket, uses one of IO::Socket::SSL or Net::SSL.

    It chooses by looking to see if $IO::Socket::SSL::VERSION is defined (ie the module's already loaded) and uses that if so.

    If not, it first tries Net::SSL, then IO::Socket::SSL only if that can't be loaded.

    Outside of mod_perl, you'll get Net::SSL. Inside of mod_perl, if you are using IO::Socket::SSL elsewhere (and I know we are, since I know the code in question ;), you'll get it instead.

    This happened to me once before, but at the time I didn't have the ambition to find out _why_ it didn't work when IO::Socket::SSL was used by the module. I just hacked around it (set $IO::Socket::SSL::VERSION to undef just long enough to fool it into using Net::SSL) and went on my way.

    - Matt Riffle
      Sr. Systems Programmer, pair Networks, Inc.
      (although, I speak only for myself; code is untested unless otherwise stated)

      One possibility: the module Net::HTTPS, used by LWP::Protocol::https::Socket, uses one of IO::Socket::SSL or Net::SSL

      Yes, that was exactly it, thanks!

      (set $IO::Socket::SSL::VERSION to undef just long enough to fool it into using Net::SSL)

      .. And that solution worked for me here as well. :)

      It would be nice to know why Net::SSL works but IO::Socket::SSL doesn't. But that is a problem for another day.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://287237]
Approved by Zaxo
Front-paged by mattriff
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (10)
As of 2014-08-22 20:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (164 votes), past polls