You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by "Purcell, Scott" <sp...@ltcgroup.com> on 2001/06/20 18:50:49 UTC

ModPerl package Q

Hello,
Well, this is the last time I am going to bring this up. I am on Apache NT,
and I have the following .pm file that I believe I localized everything in
order to create a socket. The code below does work.  But it never makes a
new socket. As you can see I print out the IO::Socket::GLOB and it shows the
same 'reference' 10xff036c each time through. I realize this is because I am
not closing and undef the $sock. (see the commented close and undef towards
the end). But this works. Except if I shut down the machine I am calling the
socket on. Then it dies and never comes back unless I reboot apache. Not a
good work position to get a web site into.

But here is the catch. If I do close the socket and either undef or even
leave that commented out, I only get one send to the socket, and one reply,
but it never sends another reply to the server and never gets another
response back? But yes, it creates a new socket ref each time?

This confuses me so. If I close the socket, then it shows that I am creating
a new socket, but it never sends or gets a new response. But the rest of the
behavior is proper.

I was just hoping someone could look below, see if they see anything
obviously wrong and reply, or else I am left to believe that this is
possibly a threading issue with the sockets on NT?

I am going to switch to ActiveStates plex, but still would like to continue
striving towards getting the apache running with this code. So there is no
rush on this, it just makes no sense, and I hate to leave open-ended issues.

Thanks for your time,
Scott



package q2;

use IO::Socket;
my $sock;

sub tryQuery {
    unless ($sock) {
        print "No sock making it<br>\n";
        $sock = IO::Socket::INET->new(Proto => 'tcp', PeerAddr =>
'208.238.162.204', PeerPort => '8000') or die (@!);
        $sock->autoflush(1);
    }
    my ($querystring,$fieldlist,$dbpathlist,$type) = @_;
    print "$querystring is QS<br>\n";
    print "$fieldlist   is FL<br>\n";
    print "$dbpathlist  is DB<br>\n";
    print "$type        is TP<br>\n";

    my $message  =
"DBASEQUERY\n$type\n$querystring\nLIST\tFIELDS\n$fieldlist\nENDLIST\nLIST\tD
BASES\n$dbpathlist\nENDLIST\n";

    &ask($message);
}

sub ask {
    my $message = shift;
    print "$message is our message<br>\n";
    my $msgid = int(rand(1000));
    $message = $msgid . "\t" . $message;
    my $msgsize = length($message);
    print "here is our line " . $sock . "\%BEGIN\t$msgsize\n$message SHOIULD
BE GOLDEN";
    print $sock "\%BEGIN\t$msgsize\n$message";
    my $result = <$sock>;
    print "$result is first result from Q<br>\n";
    my $response;
    $result =~ s/\D//g;
    print "$result is should now be digits<br>\n";
    print "$sock is our sock<br>\n";
    read($sock, $response, $result);
    print "$response is our response<br>\n";
#    close($sock);
#   undef $sock;
}




1;




Scott Purcell


Re: ModPerl package Q

Posted by Joshua Chamas <jo...@chamas.com>.
"Purcell, Scott" wrote:
> 
> Hello,
> Well, this is the last time I am going to bring this up. I am on Apache NT,
> and I have the following .pm file that I believe I localized everything in
> order to create a socket. The code below does work.  But it never makes a
> new socket. As you can see I print out the IO::Socket::GLOB and it shows the
> same 'reference' 10xff036c each time through. I realize this is because I am
> not closing and undef the $sock. (see the commented close and undef towards
> the end). But this works. Except if I shut down the machine I am calling the
> socket on. Then it dies and never comes back unless I reboot apache. Not a
> good work position to get a web site into.
> 

Set in httpd.conf ThreadsPerChild 1

This problem should go away.  Its a bug I ran into for the first time
a few years back, and seems to have to do with any network sockets
that you might open.  

See http://forum.swarthmore.edu/epigone/modperl/crestehtwimp/35970707.7BBCB1F4@alumni.stanford.org
for my original post on this, showing our similar plights!

--Josh
_________________________________________________________________
Joshua Chamas                           Chamas Enterprises Inc.
NodeWorks <- Web Link Checking          Huntington Beach, CA  USA 
http://www.nodeworks.com                1-714-625-4051

Re: ModPerl package Q

Posted by Perrin Harkins <pe...@elem.com>.
> Well, this is the last time I am going to bring this up. I am on Apache
NT,
> and I have the following .pm file that I believe I localized everything in
> order to create a socket. The code below does work.  But it never makes a
> new socket. As you can see I print out the IO::Socket::GLOB and it shows
the
> same 'reference' 10xff036c each time through. I realize this is because I
am
> not closing and undef the $sock. (see the commented close and undef
towards
> the end). But this works. Except if I shut down the machine I am calling
the
> socket on. Then it dies and never comes back unless I reboot apache. Not a
> good work position to get a web site into.
>
> But here is the catch. If I do close the socket and either undef or even
> leave that commented out, I only get one send to the socket, and one
reply,
> but it never sends another reply to the server and never gets another
> response back? But yes, it creates a new socket ref each time?

It looks to me like you have a problem with scoping and closures.  Try
making $sock a global, i.e. change "my $sock;" to "use vars qw($sock);".
Then put your close and undef stuff back in.

- Perrin