#24456 [Opn->Bgs]: fgets returning different result

From: Date: Wed, 02 Jul 2003 11:29:36 +0000
Subject: #24456 [Opn->Bgs]: fgets returning different result
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-43067@lists.php.net to get a copy of this message
 ID:               24456
 Updated by:       wez@php.net
 Reported By:      chris dot baxter at ic24 dot net
-Status:           Open
+Status:           Bogus
 Bug Type:         Sockets related
 Operating System: Windows XP and Redhat 7.2
 PHP Version:      4.3.1
 New Comment:

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php

Please read the manual carefully:

"Returns a string of up to length - 1 bytes read from the file pointed
to by handle. Reading ends when length - 1 bytes have been read, on a
newline (which is included in the return value), or on EOF (whichever
comes first)."

versions < 4.3 were not following this behaviour.

However, what this really means is that your script is broken;  if you
are expecting "ACK\r\n", you should be using fread() to read 5 bytes
and then check the return value.


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

[2003-07-02 06:25:32] chris dot baxter at ic24 dot net

Description:
------------
PHP 4.2.3 works as I would expect. When doing an fgets($string,3) I get
3 char's returned, in my instance ACK.

as from 4.3.1 up to and including the new 5.0b the same code only
returns AC I then have to do a further fgets to collect the K of my
packet.


Reproduce code:
---------------
<?php
	$connect_to = "localhost";
	print "Connecting To: $connect_to <br>";
	$fp = fsockopen ($connect_to,2100,&$error,$errdesc,60);
	$out_data = "This is a test. Expecting 'ACK' returned followed a
string of data";
	fputs($fp,$out_data);
	$page = fgets($fp,3);
	print "in1: $page <br>";
	$page = fgets($fp,512);
	print "in2: $page <br>";
?>

Expected result:
----------------
in1: ACK
in2: The rest of my data

Actual result:
--------------
in1: AC
in2: KThe rest of my data


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


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



Thread (2 messages)

« previous php.bugs (#43067) next »