#49759 [NEW]: socket_read() fails to return empty string

2009-10-03 Thread chmod3 at googlemail dot com
From: chmod3 at googlemail dot com
Operating system: WinVista & FreeBSD
PHP version:  5.3.0
PHP Bug Type: Sockets related
Bug description:  socket_read() fails to return empty string

Description:

According to documentation:

"Note: socket_read() returns a zero length string ("") when there is no
more data to read."

This does not seem to be the case on my installations:
PHP 5.3.0 WinVista
PHP 5.2.11 WinVista
PHP 5.2.11 FreeBSD
PHP 5.2.10 WinVista
PHP 5.2.9 WinVista

socket_read() just hangs.

Reproduce code:
---
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$connection = socket_connect($socket, 'news.giganews.com', 119);

$response = '';
do {
  $recv = '';
  echo "START READ\n";
  $recv = socket_read($socket, 512);
  echo "END READ\n";
  var_dump($recv);
  if($recv != '') {
$response .= $recv;
  }
} while($recv != '');

echo 'OUTPUT: ' . $reply;

Expected result:

START READ
END READ
string(23) "200 News.GigaNews.Com
"
START READ
END READ
OUTPUT: 200 News.GigaNews.Com

Actual result:
--
START READ
END READ
string(23) "200 News.GigaNews.Com
"
START READ

-- 
Edit bug report at http://bugs.php.net/?id=49759&edit=1
-- 
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=49759&r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=49759&r=trysnapshot53
Try a snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=49759&r=trysnapshot60
Fixed in SVN:
http://bugs.php.net/fix.php?id=49759&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=49759&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=49759&r=alreadyfixed
Need backtrace:  
http://bugs.php.net/fix.php?id=49759&r=needtrace
Need Reproduce Script:   
http://bugs.php.net/fix.php?id=49759&r=needscript
Try newer version:   
http://bugs.php.net/fix.php?id=49759&r=oldversion
Not developer issue: 
http://bugs.php.net/fix.php?id=49759&r=support
Expected behavior:   
http://bugs.php.net/fix.php?id=49759&r=notwrong
Not enough info: 
http://bugs.php.net/fix.php?id=49759&r=notenoughinfo
Submitted twice: 
http://bugs.php.net/fix.php?id=49759&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=49759&r=globals
PHP 4 support discontinued:  http://bugs.php.net/fix.php?id=49759&r=php4
Daylight Savings:http://bugs.php.net/fix.php?id=49759&r=dst
IIS Stability:   
http://bugs.php.net/fix.php?id=49759&r=isapi
Install GNU Sed: 
http://bugs.php.net/fix.php?id=49759&r=gnused
Floating point limitations:  
http://bugs.php.net/fix.php?id=49759&r=float
No Zend Extensions:  
http://bugs.php.net/fix.php?id=49759&r=nozend
MySQL Configuration Error:   
http://bugs.php.net/fix.php?id=49759&r=mysqlcfg



#49759 [Com]: socket_read() fails to return empty string

2009-10-03 Thread chmod3 at googlemail dot com
 ID:   49759
 Comment by:   chmod3 at googlemail dot com
 Reported By:  chmod3 at googlemail dot com
 Status:   Feedback
 Bug Type: Sockets related
 Operating System: WinVista & FreeBSD
 PHP Version:  5.3.0
 New Comment:

Yes your code works only if PHP_NORMAL_READ is added. Adding
PHP_BINARY_READ or ommiting either will make it hang. I was hoping to
use binary so my script will handle the /r/n

CODE


$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$connection = socket_connect($socket, 'news.giganews.com', 119);

do {
  echo "-- START READ\n";
  $recv = socket_read($socket, 512, PHP_NORMAL_READ);
  var_dump($recv);
  echo "-- END READ\n";
} while ($recv !== '' && $recv !== FALSE && $recv !== "\n");


Previous Comments:


[2009-10-03 13:46:07] f...@php.net

I think your example code makes no sense.

When I change it a bit, it works as expected (Did you check PHP_BINARY
READ vs. PHP_NORMAL_READ?)




I do agree that the docs could be clarified.

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

[2009-10-03 12:42:42] chmod3 at googlemail dot com

Description:

According to documentation:

"Note: socket_read() returns a zero length string ("") when there is no
more data to read."

This does not seem to be the case on my installations:
PHP 5.3.0 WinVista
PHP 5.2.11 WinVista
PHP 5.2.11 FreeBSD
PHP 5.2.10 WinVista
PHP 5.2.9 WinVista

socket_read() just hangs.

Reproduce code:
---
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$connection = socket_connect($socket, 'news.giganews.com', 119);

$response = '';
do {
  $recv = '';
  echo "START READ\n";
  $recv = socket_read($socket, 512);
  echo "END READ\n";
  var_dump($recv);
  if($recv != '') {
$response .= $recv;
  }
} while($recv != '');

echo 'OUTPUT: ' . $reply;

Expected result:

START READ
END READ
string(23) "200 News.GigaNews.Com
"
START READ
END READ
OUTPUT: 200 News.GigaNews.Com

Actual result:
--
START READ
END READ
string(23) "200 News.GigaNews.Com
"
START READ





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



#49759 [Fbk->Opn]: socket_read() fails to return empty string

2009-10-04 Thread chmod3 at googlemail dot com
 ID:   49759
 User updated by:  chmod3 at googlemail dot com
 Reported By:  chmod3 at googlemail dot com
-Status:   Feedback
+Status:   Open
 Bug Type: Sockets related
 Operating System: WinVista & FreeBSD
 PHP Version:  5.3.0
 New Comment:

So is socket_read() supposed to hang by design when in PHP_BINARY_READ
mode when there is no more data to read?


Previous Comments:


[2009-10-03 14:14:53] chmod3 at googlemail dot com

Yes your code works only if PHP_NORMAL_READ is added. Adding
PHP_BINARY_READ or ommiting either will make it hang. I was hoping to
use binary so my script will handle the /r/n

CODE


$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$connection = socket_connect($socket, 'news.giganews.com', 119);

do {
  echo "-- START READ\n";
  $recv = socket_read($socket, 512, PHP_NORMAL_READ);
  var_dump($recv);
  echo "-- END READ\n";
} while ($recv !== '' && $recv !== FALSE && $recv !== "\n");



[2009-10-03 13:46:07] f...@php.net

I think your example code makes no sense.

When I change it a bit, it works as expected (Did you check PHP_BINARY
READ vs. PHP_NORMAL_READ?)




I do agree that the docs could be clarified.

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

[2009-10-03 12:42:42] chmod3 at googlemail dot com

Description:

According to documentation:

"Note: socket_read() returns a zero length string ("") when there is no
more data to read."

This does not seem to be the case on my installations:
PHP 5.3.0 WinVista
PHP 5.2.11 WinVista
PHP 5.2.11 FreeBSD
PHP 5.2.10 WinVista
PHP 5.2.9 WinVista

socket_read() just hangs.

Reproduce code:
---
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$connection = socket_connect($socket, 'news.giganews.com', 119);

$response = '';
do {
  $recv = '';
  echo "START READ\n";
  $recv = socket_read($socket, 512);
  echo "END READ\n";
  var_dump($recv);
  if($recv != '') {
$response .= $recv;
  }
} while($recv != '');

echo 'OUTPUT: ' . $reply;

Expected result:

START READ
END READ
string(23) "200 News.GigaNews.Com
"
START READ
END READ
OUTPUT: 200 News.GigaNews.Com

Actual result:
--
START READ
END READ
string(23) "200 News.GigaNews.Com
"
START READ





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



#49759 [Opn->Bgs]: socket_read() fails to return empty string

2009-10-04 Thread chmod3 at googlemail dot com
 ID:   49759
 User updated by:  chmod3 at googlemail dot com
 Reported By:  chmod3 at googlemail dot com
-Status:   Open
+Status:   Bogus
 Bug Type: Sockets related
 Operating System: WinVista & FreeBSD
 PHP Version:  5.3.0
 New Comment:

Understood, so it's a documentation 'bug'.


Previous Comments:


[2009-10-04 18:09:40] sjo...@php.net

socket_read() intentionally blocks until there is some data.



[2009-10-04 09:42:15] chmod3 at googlemail dot com

So is socket_read() supposed to hang by design when in PHP_BINARY_READ
mode when there is no more data to read?



[2009-10-03 14:14:53] chmod3 at googlemail dot com

Yes your code works only if PHP_NORMAL_READ is added. Adding
PHP_BINARY_READ or ommiting either will make it hang. I was hoping to
use binary so my script will handle the /r/n

CODE


$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$connection = socket_connect($socket, 'news.giganews.com', 119);

do {
  echo "-- START READ\n";
  $recv = socket_read($socket, 512, PHP_NORMAL_READ);
  var_dump($recv);
  echo "-- END READ\n";
} while ($recv !== '' && $recv !== FALSE && $recv !== "\n");



[2009-10-03 13:46:07] f...@php.net

I think your example code makes no sense.

When I change it a bit, it works as expected (Did you check PHP_BINARY
READ vs. PHP_NORMAL_READ?)




I do agree that the docs could be clarified.

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

[2009-10-03 12:42:42] chmod3 at googlemail dot com

Description:

According to documentation:

"Note: socket_read() returns a zero length string ("") when there is no
more data to read."

This does not seem to be the case on my installations:
PHP 5.3.0 WinVista
PHP 5.2.11 WinVista
PHP 5.2.11 FreeBSD
PHP 5.2.10 WinVista
PHP 5.2.9 WinVista

socket_read() just hangs.

Reproduce code:
---
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$connection = socket_connect($socket, 'news.giganews.com', 119);

$response = '';
do {
  $recv = '';
  echo "START READ\n";
  $recv = socket_read($socket, 512);
  echo "END READ\n";
  var_dump($recv);
  if($recv != '') {
$response .= $recv;
  }
} while($recv != '');

echo 'OUTPUT: ' . $reply;

Expected result:

START READ
END READ
string(23) "200 News.GigaNews.Com
"
START READ
END READ
OUTPUT: 200 News.GigaNews.Com

Actual result:
--
START READ
END READ
string(23) "200 News.GigaNews.Com
"
START READ





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