ID:               22199
 Updated by:       [EMAIL PROTECTED]
-Summary:          Strange behavior of fgets() in conjunction with
                   fputs()
 Reported By:      [EMAIL PROTECTED]
-Status:           Suspended
+Status:           Assigned
 Bug Type:         Sockets related
 Operating System: Suse Linux 7.2
 PHP Version:      4CVS-2003-02-12 (stable)
-Assigned To:      
+Assigned To:      wez
 New Comment:

Change summary, assign to me, patch pending.


Previous Comments:
------------------------------------------------------------------------

[2003-02-13 14:06:15] [EMAIL PROTECTED]

Ok... here you go. While writing this script for you, i found the real
problemmaker. But first the script:

<?php

#
# Strange behavior of fgets() in conjunction with fputs()
#

$sock = fsockopen('217.160.132.63', 6667, $errno, $errstr, 30);
if($sock) {
        echo "Connection established...\n";

        // Services details
        $conpass = 'a_nice_password';
        $servern = 'testing.xanaducorp.net';
        $serverdsc = 'doing tests';

        // Incomming-traffic logger details
        $ircNick    = "log_printer2";
        $bot_ident = "printer2";
        $bot_name = "printer2";
        $bot_host = "testing.xanaducorp.net";
        $logchannel = '#services';

        # Handshake with server
        fputs($sock, "PASS $conpass"."\n");
        fputs($sock, "SERVER $servern 1 :$serverdsc"."\n");
        fputs($sock, "CAPAB :"."\n");
        fputs($sock, "SVINFO 3 1 0 :".time()."\n");
        fputs($sock, "PONG ".time()."\n");

        fputs($sock, "NICK $ircNick 1 ".time()." $bot_ident $bot_host $servern
:$bot_name"."\n");
        fputs($sock, ":$ircNick MODE $ircNick :+Si"."\n");
        fputs($sock, ":$ircNick JOIN $logchannel"."\n");
        fputs($sock, ":$servern MODE $logchannel +o $ircNick"."\n");

   while($buffer = fgets($sock)) {

        echo $buffer;
        flush();
                $i++;


                #
                # This fputs() is creating all the problems. I'll explain below
                #
                if($i==1) fputs($sock, ":$ircNick PRIVMSG $logchannel
:".$buffer."\n");
        }

        fclose ($handle);
        echo "Connection closed...\n";
} else {
        echo "$errstr ($errno)<br>\n";
}

?>

As you can see, i did for testing purposes send all the text send from
the irc server to my service to stdout and had a look at it. Everything
was working great as long as i do not have a fputs() in the while-loop.
When only submitting one single line in fputs() 125 lines of input from
the server a simply lost.

I will short output of both version:
Without fputs():

Connection established...
:irc.xanaducorp.net NOTICE AUTH :*** Looking up your hostname...
:irc.xanaducorp.net NOTICE AUTH :*** Found your hostname (cached)
[... additonal 122 lines ...]
:Netvyper JOIN #xanadu.eve,#eve.beta,#eve
NICK Cimager 1 1045158878 ~Twis cimager.xs4all.nl irc.xanaducorp.net 0
:Cim


With fputs():
Connection established...
:irc.xanaducorp.net NOTICE AUTH :*** Looking up your hostname...
 ~Twis cimager.xs4all.nl irc.xanaducorp.net 0 :Cim


That is really strange. I hope this is what you did requested.

------------------------------------------------------------------------

[2003-02-13 11:48:23] [EMAIL PROTECTED]

Suspending until you can provide the short, self contained, reproducing
script we have requested.

------------------------------------------------------------------------

[2003-02-13 08:31:07] [EMAIL PROTECTED]

Ok, as it seems the socket functions do work. So I will use them for
now with PHP 4.3.x ... still the bug in fgets() is there. Trust me.
It's not my stupidity.

------------------------------------------------------------------------

[2003-02-13 08:10:22] [EMAIL PROTECTED]

Btw, i check SmartIRC, that [EMAIL PROTECTED] is using. Actually this
class does not use fgets() at all, because it either uses real sockets
or fread().

------------------------------------------------------------------------

[2003-02-13 07:33:51] [EMAIL PROTECTED]

Sockets are set to non-blocking after searching a while in doc after
first notice of this problem. Tho it did not effect the main problem i
have.

If fgets() would return a false, then the while function would stop.
This does not happen, so fgets() does not return a false.

Yes, i used stream_set_timeout() with php 4.3.x (not needed in 4.2.3)
with a timeout of 600 seconds. This is clearly enough, because my
server pings every 60s anyway.

As already said before, the irc services are 100% working with php
4.2.3 and they are running for over 5 month already. I only updated to
4.3.x and the problems started. First i had to find out, that there are
now new functions needed (mainly to set to non-blocking - setting a
timeout is not really needed i think), but somehow this did not solve
the main problem i had. The code i sent you is ofc much too short, but
still it's the main functions that produce the error, none else are
needed. All the handshakes and stuff are left away, because of security
issues. I'm for sure using correct server2server protocol for my ircd
(see above)

------------------------------------------------------------------------

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/22199

-- 
Edit this bug report at http://bugs.php.net/?id=22199&edit=1

Reply via email to