php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #6621 Socket handling is not working correctly.
Submitted: 2000-09-08 01:59 UTC Modified: 2000-09-28 20:51 UTC
From: csa at elogica dot com dot br Assigned:
Status: Closed Package: *Network Functions
PHP Version: 4.0.2 OS: Linux RH 6.2 and others
Private report: No CVE-ID: None
 [2000-09-08 01:59 UTC] csa at elogica dot com dot br
I was trying to make a webchat connecting to an IRC server, but I was getting problems with the connection. It connected OK, but I can't write ANYTHING. When I submit (input.php) text to be sent to the server, it just stalls.
Then I got a ready-made script called phpChat, which used phpIRC to do the same thing. And it had the same problem. I tried also a free webhost that supplied MySQL and PHP4 and got the *same* problem. Then I was told that it was a PHP4 bug, and that it worked fine in PHP3 and even on PHP4 up to b3. I tested it on PHP 3.0.16 and it phpChat works FINE!

There goes MY (very very simple) code:

CONN.PHP:
<?php
session_start();
?>
<HTML><BODY>
<?php
session_register("buffer");
$fp = fsockopen("irc.elogica.com.br", 7000, &$errno, &$errstr);
//set_socket_blocking($fp,0);
if(!$fp) {
echo "$errstr ($errno)<br>\n";
} else {
session_register("fp");
fputs($fp,"NICK Teste\n");
fputs($fp,"USER Teste 1 2 :Teste\n");
while(!feof($fp)) {
$linha = fgets($fp,128);
if ($linha) echo str_replace("\n", "<br>\n", $linha);
flush();
if ($buffer)
{
  echo $buffer + "<br>\n";
  $buffer = 0;
}
}
fclose($fp);
}
?>
</BODY></HTML>

INPUT.PHP:
<?php
session_start();
session_register("buffer");
session_register("fp");
?>
<HTML><BODY>
<FORM ACTION="input.php" METHOD="POST">
Vamu l?: <input type="text" name="texto">
<input type="hidden" name="SID" value="<?=session_id()?>">
</FORM>
<?php
if ($texto) $buffer = $texto;
flush();
if (isset($fp) && !feof($fp) && $texto)
{
 fputs($fp, $texto + "\n");
 fflush($fp);
}
?>
</HTML></BODY>

My configure line:
./configure --with mysql --with-apxs --enable sysvshm --enable-sysvsem

(it has the same problem without the SYSV stuff).





Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-09-08 08:11 UTC] csa at elogica dot com dot br
I was trying to make a webchat connecting to an IRC server, but I was getting problems
with the connection. It connected OK, but I can't write ANYTHING. When I submit (input.php)
text to be sent to the server, it just stalls.
Then I got a ready-made script called phpChat, which used phpIRC to do the same thing. And
it had the same problem. I tried also a free webhost that supplied MySQL and PHP4 and got
the *same* problem. Then I was told that it was a PHP4 bug, and that it worked fine in PHP3
and even on PHP4 up to b3. I tested it on PHP 3.0.16 and it phpChat works FINE!

There goes MY (very very simple) code:

CONN.PHP:
<?php
session_start();
?>
<HTML><BODY>
<?php
session_register("buffer");
$fp = fsockopen("irc.elogica.com.br", 7000, &$errno, &$errstr);
//set_socket_blocking($fp,0);
if(!$fp) {
echo "$errstr ($errno)<br>\n";
} else {
session_register("fp");
fputs($fp,"NICK Teste\n");
fputs($fp,"USER Teste 1 2 :Teste\n");
while(!feof($fp)) {
$linha = fgets($fp,128);
if ($linha) echo str_replace("\n", "<br>\n", $linha);
flush();
if ($buffer)
{
  echo $buffer + "<br>\n";
  $buffer = 0;
}
}
fclose($fp);
}
?>
</BODY></HTML>

INPUT.PHP:
<?php
session_start();
session_register("buffer");
session_register("fp");
?>
<HTML><BODY>
<FORM ACTION="input.php" METHOD="POST">
Vamu l?: <input type="text" name="texto">
<input type="hidden" name="SID"
value="<?=session_id()?>">
</FORM>
<?php
if ($texto) $buffer = $texto;
flush();
if (isset($fp) && !feof($fp) && $texto)
{
 fputs($fp, $texto + "\n");
 fflush($fp);
}
?>
</HTML></BODY>

My configure line:
./configure --with mysql --with-apxs --enable sysvshm --enable-sysvsem

(it has the same problem without the SYSV stuff).

phpChat and phpIRC can be found at http://www.phpwizard.net/
 [2000-09-25 19:32 UTC] stas@php.net
I guess that you should not pass file resource in session variable. It is not expected to exist and be in the same state in the second script.
 [2000-09-28 20:51 UTC] csa at elogica dot com dot br
Ok. I can't say that my code is correct, because I couldn't even make it work (tried several changes). But *please* get phpChat and phpIRC at www.phpwizard.net, install and try them. I have them running on php 3.0.16, but they don't work on php4.0.1pl2 neither php4.0.2 because of this socket bug.

Thanks.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 09:01:27 2024 UTC