php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #24101 socket_select call is blocking and never returning
Submitted: 2003-06-09 14:02 UTC Modified: 2003-06-10 10:07 UTC
From: wzaccone at telcordia dot com Assigned:
Status: Not a bug Package: Sockets related
PHP Version: 4.3.2 OS: Solaris 5.8 / Sparc
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: wzaccone at telcordia dot com
New email:
PHP Version: OS:

 

 [2003-06-09 14:02 UTC] wzaccone at telcordia dot com
we upgraded our application from php 4.1.2 to 4.3.2 and are testing. and found the following code no longer works:

if (@socket_select($socketsCopy, $w = NULL, $e = NULL, $tv = NULL) !== FALSE){

      foreach($socketsCopy as $sock){

The socket_select call appears to be never returning with php 4.3.2.. code worked correctly with 4.1.2.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-06-09 23:40 UTC] sniper@php.net
Could you give a complete (but short, please) script
that shows this problem clearly..? (can't reproduce, but I'm propably missing some part here..)

 [2003-06-10 09:02 UTC] wzaccone at telcordia dot com
function readMsgsFromHosts($sockets){
  
   set_time_limit(0);
   $numSockets = count($sockets);
   
   $keys = array_keys($sockets);
    
   $socketsCopy = Array();

    foreach ($keys as $key){
      $socketsCopy[$key] = $sockets[$key];
    }

    if (@socket_select($socketsCopy, $w = NULL, $e = NULL, $tv = NULL) !== FALSE){

      foreach($socketsCopy as $sock){

          $string = fread($sock, $readAmount);
 [2003-06-10 09:19 UTC] wez@php.net
You can't use fread() on sockets returned from the sockets extension, and likewise, you can use socket_select() on streams returned from fopen() or fsockopen().

Perhaps you meant to use stream_select() instead?
 [2003-06-10 09:23 UTC] wzaccone at telcordia dot com
thank you for the info.. we were previously using socket_select and fread successfully with 4.1.2 and went live with an application doing so.  For our next release, we upgraded to PHP 4.3.2 and it stopped working.  Can I assume that this behavior has changed with 4.3.2?? therefore we must migrate to using streams_select to upgrade to 4.3.2?
 [2003-06-10 09:39 UTC] wez@php.net
Looking at the CVS history, there is no way that your code should work in 4.1.2 (socket_select() didn't even accept arrays as parameters back then), nor even in 4.2.x (which only accepted the socket extensions own descriptors).  The chances are that it only worked as a fluke.

The sockets extension has always been documented as experimental, so functionality change from flaky code that is 18 months old is allowed, without notice.

It is highly recommended that you update your code to use the stream_select() function provided in PHP 4.3.x, as it is more flexible and an officially supported (stable!) API.

This is not a bug in PHP, so I'm marking this report as Bogus.
 [2003-06-10 10:07 UTC] wzaccone at telcordia dot com
I can only assume it was working by accident with 4.1.2.  We have changed our code today to use streams_select as per your advice, and the problem has been solved. Thanks very much for your assistance.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Apr 08 06:01:25 2020 UTC