|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-02-12 22:16 UTC] darkevil at darkevil dot de
I have written a IRC Nickserv/Authserv/Chanserv bot in php. Using a socket connection to the irc server. After updating from php 4.2.3 to 4.3.1-dev (tried stable version of 7.2 and 13.2) fgets() reacts very strange.
The main code (very simplified), that produces the error is this:
$sock = fsockopen($ircServer, $ircPort);
while($line = fgets($sock)) {
echo $line;
}
fclose($sock);
While handshaking and exchanging data between the irc bot and the irc server there are more than 200 lines of text, that is sent to the bot. Using PHP 4.2.3 all the lines are displayed. Using PHP 4.3.1-dev only two lines are returned. The first line of the whole text and a part of a line inbetween. Nothing else. Also, when a user sends the command:
/join #test,#test1,#test2,#test3
fgets() in PHP 4.3.1-dev only returns /join #test
That is a very strange behavior i must say.
May configuration line:
./configure --prefix=/usr/share --datadir=/usr/share/php --bindir=/usr/bin --libdir=/usr/share --with-config-file-path=/etc --with-exec-dir=/usr/lib/php/bin --with-mysql=/usr --with-gd=yes --enable-gd-native-ttf --enable-gd-imgstrttf --with-tiff-dir=/usr --with-jpeg-dir=/usr --with-png-dir=/usr --with-xpm-dir=/usr/X11R6 --with-ldap=yes --with-zlib=yes --with-bz2 --with-gmp --with-xml --with-ttf --with-t1lib --with-mcal=/usr --with-imap-ssl=yes --with-sablot --with-ftp --with-ndbm --with-gdbm --with-mcrypt --with-gettext --with-gd=yes --enable-versioning --enable-yp --enable-bcmath --enable-trans-sid --enable-inline-optimization --enable-track-vars --enable-magic-quotes --enable-safe-mode --enable-sockets --enable-sysvsem --enable-sysvshm --enable-shmop --enable-calendar --enable-mbstring --enable-mbstr-enc-trans --enable-exif --enable-ftp --enable-memory-limit --enable-wddx --enable-filepro --enable-dbase --enable-ctype --disable-debug --enable-force-cgi-redirect --enable-discard-path --enable-sigchild
I hope this bug report is in any way usefull =)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 00:00:02 2025 UTC |
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.