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

 ID:                 33471
 Comment by:         bneff84 at gmail dot com
 Reported by:        info at goldenelite dot com
 Summary:            socket_read PHP_NORMAL_READ blocks socket
 Status:             No Feedback
 Type:               Bug
 Package:            Sockets related
 Operating System:   FreeBSD 4.10
 PHP Version:        5.0.4
 Block user comment: N
 Private report:     N

 New Comment:

I've just encountered this with PHP 5.3.4 running as FastCGI on Apache
in CentOS.



After consulting the documentation in light of finding this bug report I
do believe the documentation covers why this is happening, but I do
believe it would still be considered a bug.



Doc says: PHP_NORMAL_READ - reading stops at \n or \r.



I think technically this means regardless of what you enter as the
second parameter, the function will not stop reading until it encounters
a newline character. This is probably why it appears to be "blocking"
even when set to nonblocking because it is attempting to read until a
newline is encountered.



Technically this would still be a bug IMO because the expected behavior
of nonblocking socket reading is that it should immediately return
whatever it found regardless of if it filled it's "buffer" by finding
the line end.


Previous Comments:
------------------------------------------------------------------------
[2009-09-11 05:19:32] alonsoalonsocr at yahoo dot com

this bug exists in 5.2.9 on Linux (either documentation has still not
been fixed, or function does not respect blocking or timout setting. I
should add that setting a read timeout with socket_set_option has no
effect, it still blocks forever when using PHP_NORMAL_READ

------------------------------------------------------------------------
[2007-08-20 00:04:43] piro at pirocast dot net

bug still exists as of PHP 5.2.4

------------------------------------------------------------------------
[2005-07-04 01:00:04] php-bugs at lists dot php dot net

No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".

------------------------------------------------------------------------
[2005-06-26 13:14:04] sni...@php.net

Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip



------------------------------------------------------------------------
[2005-06-25 07:36:17] info at goldenelite dot com

Description:
------------
The socker_read function has two modes: PHP_BINARY_READ and
PHP_NORMAL_READ. The latter is useful to get lines instead of raw data.
But using it will result in a blocked socket, regardless of
socket_set_nonblock() has been used.



I'm not sure this is a bug. If it is not, the manual page should mention
that the socket_read function would block regardless of blocking mode if
the PHP_NORMAL_READ parameter is used.

Reproduce code:
---------------
// short example

$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);

socket_set_nonblock($socket);

socket_connect($socket, $host, $port);

$data = socket_read($socket, 512, PHP_NORMAL_READ);

Expected result:
----------------
Let's assume no data is transmitted by the remote host, thus no data is
to be received. Since we set non-blocking mode, the socket_read function
should produce a socket error very quickly and the script execution
continues.

Actual result:
--------------
Instead of continuing script execution, the socket_read function blocks
the further execution, waiting for data to be read until its buffer is
full. Thus it shows the effect of blocking mode, even though we
explicitly set to non blocking mode.


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



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

Reply via email to