socket_select

FunctionParams and return types changed in PHP 8.0

Runs the select() system call on the given arrays of sockets with a specified timeout.

PHP 5
PHP 7
PHP 8.0
Improved
PHP 8.1
PHP 8.2-8.3
PHP 8.4
PHP 8.5
PHP 8.6

socket_select Function synopsis

socket_select(
    ?array &$read,
    ?array &$write,
    ?array &$except,
    ?int $seconds,
    int $microseconds = 0
  ): int|false

Parameters

$read

Passed by referenceType?array

The sockets listed in the $read array will be watched to see if characters become available for reading (more precisely, to see if a read will not block - in particular, a socket is also ready on end-of-file, in which case a socket_read will return a zero length string).

$write

Passed by referenceType?array

The sockets listed in the $write array will be watched to see if a write will not block.

$except

Passed by referenceType?array

The sockets listed in the $except array will be watched for exceptions.

$seconds

Type?int

The $seconds and $microseconds together form the timeout parameter. The timeout is an upper bound on the amount of time elapsed before socket_select return. $seconds may be zero , causing socket_select to return immediately. This is useful for polling. If $seconds is null (no timeout), socket_select can block indefinitely.

$microseconds

OptionalTypeintDefault value0

Note that the parameters $read, $write, and $except are passed by reference, and contain additional/updated context data that may be useful.

Return value

Typeint|false

On success socket_select returns the number of sockets contained in the modified arrays, which may be zero if the timeout expires before anything interesting happens.On error false is returned. The error code can be retrieved with socket_last_error.

Be sure to use the `===` operator when checking for an
error. Since the [`socket_select`](/codex/socket_select) may return 0 the
comparison with `==` would evaluate to `true`:

Changes to the socket_select Function

PHP 8.0

  • Return type added: int|false
  • Parameter name of parameter #1 changed: $read_fds to $read
  • Parameter type added for parameter #1 ($read): ?array
  • Parameter name of parameter #2 changed: $write_fds to $write
  • Parameter type added for parameter #2 ($write): ?array
  • Parameter name of parameter #3 changed: $except_fds to $except
  • Parameter type added for parameter #3 ($except): ?array
  • Parameter name of parameter #4 changed: $tv_sec to $seconds
  • Parameter type added for parameter #4 ($seconds): ?int
  • Parameter name of parameter #5 changed: $tv_usec to $microseconds
  • Parameter type added for parameter #5 ($microseconds): int
  • Parameter default value added for position #5 ($microseconds): 0
  socket_select(
-     &$read_fds,
+     ?array &$read,
-     &$write_fds,
+     ?array &$write,
-     &$except_fds,
+     ?array &$except,
-     $tv_sec,
+     ?int $seconds,
-     $tv_usec
+     int $microseconds = 0
-   )
+   ): int|false

socket_select Function Availability

PHP VersionAvailability
PHP 8.6Upcoming Release Yes
PHP 8.5Supported (Latest) Yes
PHP 8.4Supported Yes
PHP 8.3Security-Fixes Only Yes
PHP 8.2Security-Fixes Only Yes
PHP 8.1Unsupported Yes
PHP 8.0Unsupported Yes
PHP 7.4Unsupported Yes
PHP 7.3Unsupported Yes
PHP 7.2Unsupported Yes
PHP 7.1Unsupported Yes
PHP 7.0Unsupported Yes
PHP 5.6Unsupported Yes
PHP 5.5Unsupported Yes
PHP 5.4Unsupported Yes
PHP 5.3Unsupported Yes