php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #2760 Failure to read from Windows sockets
Submitted: 1999-11-18 21:46 UTC Modified: 2002-06-16 09:00 UTC
From: pjones at ssc dot nmfs dot gov Assigned:
Status: Not a bug Package: Misbehaving function
PHP Version: 3.0.12 OS: Mandrake Linux 6.1
Private report: No CVE-ID: None
 [1999-11-18 21:46 UTC] pjones at ssc dot nmfs dot gov
We have php 3.0.12/apache running on a Mandrake Linux 6.1 server, attempting to communicate with a socket on a Windows NT 4.0 sp5 machine.  Write operations to the socket are successful, but reading back from the socket always blocks until timeout.

Here's what's supposed to happen:
1. PHP opens a socket to the Windows machine
2. PHP writes a string (a processing instruction to the app on Windows)
3. The app on Windows writes a reply back to PHP
4. PHP reads the reply into a variable, etc etc

Steps 1-3 work correctly.  However, php always fails to read back the reply from the Windows application using any number of approaches, such as:

function doTest(&$command) {
  $reply;
  $fp = fsockopen("marlin.ssc.nmfs.gov", 6692, &$errno, &$errstr, 30);
  if(!$fp) {
    return "Error opening socket.";
  } else {
    fputs($fp,$command);
    while ($buffer = fgets($fp, 128)) {
      $reply .= $buffer;
    }
    fclose($fp);
  }
  return $reply;
}

or replace the fgets with calls to fgetc, or any other piece of file-reading code.

Note the similarity to jisun66@hotmail.com's comment on the fgets manual page online, and the similarity to bug #2493.

FWIW, reading from the windows socket using a java program works without a hitch, so it does appear to be a php-specific problem.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-11-19 19:43 UTC] danny at cvs dot php dot net
I had a similar problem where the NT App did not terminate 
the reply with a newline but with a ">" prompt character.

Replacing the fgets() with an fgtec() loop that stopped on 
detecting the terminating ">" promt solved the mystery. 
must a lot slower, but it worked.

I use PHP 3.013-dev though (compiled from CVS about a month 
ago).
 
Danny
---
 [2002-06-16 09:00 UTC] sander@php.net
Thank you for taking the time to report a problem with PHP.
Unfortunately, PHP 3 is no longer supported. Please download
the latest version of PHP 4 from http://www.php.net/downloads.php

If you are able to reproduce the bug with one of the latest
versions of PHP, please change the PHP version on this bug report
to the version you tested and change the status back to "Open".
Again, thank you for your continued support of PHP.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 18:01:28 2024 UTC