|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48249 socket_read() not returning on no more data to read
Submitted: 2009-05-12 19:54 UTC Modified: 2009-07-10 01:00 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: z4ns4tsu at gmail dot com Assigned:
Status: No Feedback Package: Sockets related
PHP Version: 5.2.9 OS: Windows XP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: z4ns4tsu at gmail dot com
New email:
PHP Version: OS:


 [2009-05-12 19:54 UTC] z4ns4tsu at gmail dot com
I am initiating a socket to an SMTP server to send a message. After transmitting the EHLO, I need to wait for a variable number of lines to be returned, so I am using a do{..}while() loop to check if there is nothing more to be read from the socket before sending the next command.  The program, however, falls into an endless wait because socket_read() is never returning an empty string (like the documentation says it will) or FALSE (like some other bug reports say it will).

I have tried with both the PHP_BINARY_READ and PHP_NORMAL_READ flags set as well as with no flags set at all.

Reproduce code:
foreach($mail_head as $in) {
  $output = "";
  $in .= "\r\n";
  echo $in;
  @socket_write($socket, $in, strlen($in)) or die("Error writing to socket: " . socket_strerror(socket_last_error()));
  do {
    $out = false;
    $out = socket_read($socket, 1024);
    $output .= $out;
  } while($out !== false && $out !== '');
  if(!preg_match('/^[23]/', $output)) {
    die("Error: Mail server did not return the expected response.");

Expected result:
EHLO fake.domain
250-this server offers 4 extensions
250-SIZE 30485760
MAIL FROM:<address@fake.domain>
250 Requested mail action okay, completed

Actual result:
EHLO fake.domain


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-05-14 21:58 UTC]
What DOES it return? Put 'var_dump($out);' inside the loop.
 [2009-05-18 19:30 UTC] z4ns4tsu at gmail dot com
string(133) " [], this server offers 4 extensions
250-SIZE 30485760

And then it hangs.
 [2009-07-02 22:09 UTC]
Please provide a complete but short example script. I can not reproduce 
this with proper script and using Linux.
 [2009-07-10 01:00 UTC] 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".
 [2010-09-29 04:15 UTC] payahnih at hotmail dot com
I experienced the same issue on Windows XP, PHP 5.3.3.
It is silly trying to reproduce the issue in Linux, where as the problem is happening under Windows XP, as in the original report.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jul 20 12:01:28 2024 UTC