Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9318041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T03:01:14+00:00 2026-06-19T03:01:14+00:00

I’m playing with socket_select , but on one hosting, this function does strange things:

  • 0

I’m playing with socket_select, but on one hosting, this function does strange things:

  • returns immediately, instead of waiting 5 seconds
  • returns false, indicating some error
  • but socket_last_error() returns 0 (success).

phpinfo() of this server: http://jsfiddle.net/Lmrfe/embedded/result/

$server = socket_create( AF_UNIX, SOCK_STREAM, 0 );
$r = socket_bind( $server, '/some/file/somewhere');
$r = socket_listen( $server );
// none of the above socket_* returns false

$t = microtime(true);
socket_clear_error();

$read = array( $server ); $write = null; $except = null;
$read = array( $server ); $write = array(); $except = array();
$read = array(); $write = array(); $except = array();
$read = null; $write = null; $except = null;

$changed = socket_select( $read, $write, $except, 5,0 );
$changed = socket_select( $read, $write, $except, null );
$changed = socket_select( $read, $write, $except, 5000000 );
$changed = socket_select( $read, $write, $except, 5000000, 0 );
$changed = socket_select( $read, $write, $except, 5000000, 5000000 );

/* Results:

   microtime(true) - $t  == almost zero

   $changed === false

   socket_last_error() === 0
   socket_strerror(socket_last_error()) === Success

   $read === array(1) {
     [0]=>
     resource(2) of type (Socket)
   }
   $write  === NULL
   $except === NULL
*/

$s = socket_read( $server, 1024, PHP_BINARY_READ );
// $s === false

What is happening here?

Updated test script: still runs in an instant:

header('Content-Type: text/plain; charset=utf-8');
error_reporting(-1);

for( $i = 0; $i < 4; $i++ ){
for( $j = 0; $j < 5; $j++ ){
  echo "\n\n\n\n\n[i,j]=[{$i},{$j}]\n";

  $socket = socket_create( AF_UNIX, SOCK_STREAM, 0 );
  var_dump('socket_create', $socket ); echo "\n"; if( $socket === false ) continue;

  $socket_file = dirname(__FILE__)."/test_socket_i{$i}_j{$j}";
  if( file_exists( $socket_file )) unlink( $socket_file );

  $r = socket_bind( $socket, $socket_file );
  var_dump('socket_bind', $r ); echo "\n"; if( $r === false ) continue;

  $r = socket_listen( $socket );
  var_dump('socket_listen', $r ); echo "\n"; if( $r === false ) continue;

  $t = microtime(true);
  socket_clear_error();

  if($i==0){ $read = null;             $write = null;    $except = null; }
  if($i==1){ $read = array();          $write = array(); $except = array(); }
  if($i==2){ $read = array( $socket ); $write = null;    $except = null; }
  if($i==3){ $read = array( $socket ); $write = array(); $except = array(); }

  if($j==0){ $changed = socket_select( $read, $write, $except, 5,0 ); } // 5 seconds
  if($j==1){ $changed = socket_select( $read, $write, $except, null ); } // forever
  if($j==2){ $changed = socket_select( $read, $write, $except, 5000000 ); }
  if($j==3){ $changed = socket_select( $read, $write, $except, 5000000, 0 ); }
  if($j==4){ $changed = socket_select( $read, $write, $except, 5000000, 5000000 ); }

  var_dump('•socket_select returned:', $changed );echo "\n";
  var_dump('•$read/$write/$except:',$read,$write,$except);echo "\n";
  var_dump('•error:', socket_last_error(), socket_strerror(socket_last_error()) );echo "\n";
  var_dump('time: ', microtime(true) - $t );echo "\n";               // almost zero
}}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T03:01:15+00:00Added an answer on June 19, 2026 at 3:01 am

    If you run into this bug, you could use something similar to work it around:

    $socket_select_timeout_seconds = 5;
    
    while(true){
      $time_start = microtime(true);
      $c = socket_select($r,$w,$e, $socket_select_timeout_seconds );
    
      if( /* something happened */ ){
        // handle socket events
      }else if( microtime(true) - $time_start < 0.01){
        // nothing happened, but buggy socket_select didn't wait
        // wait manually
        usleep( $socket_select_timeout_seconds * 1000000 );
      }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
Does anyone know how can I replace this 2 symbol below from the string
I want to construct a data frame in an Rcpp function, but when I
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.