stream_socket_server

FunctionParams changed in PHP 8.0

Create an Internet or Unix domain server socket.

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

stream_socket_server Function synopsis

stream_socket_server(
    string $address,
    &$error_code = null,
    &$error_message = null,
    int $flags = STREAM_SERVER_BIND | STREAM_SERVER_LISTEN,
    $context = null
  )

Parameters

$address

Typestring

The type of socket created is determined by the transport specified using standard URL formatting: transport://target.

$error_code

Passed by reference, OptionalDefault valuenull

If the optional $error_code and $error_message arguments are present they will be set to indicate the actual system level error that occurred in the system-level socket(), bind(), and listen() calls. If the value returned in $error_code is 0 and the function returned false, it is an indication that the error occurred before the bind() call. This is most likely due to a problem initializing the socket. Note that the $error_code and $error_message arguments will always be passed by reference.

$error_message

Passed by reference, OptionalDefault valuenull

See $error_code description.

$flags

OptionalTypeintDefault valueSTREAM_SERVER_BIND | STREAM_SERVER_LISTEN

A bitmask field which may be set to any combination of socket creation flags.

$flags accepts one or a bitmask of the following constant values:

$context

OptionalDefault valuenull

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

Changes to the stream_socket_server Function

PHP 8.0

  • Parameter name of parameter #1 changed: $localaddress to $address
  • Parameter type added for parameter #1 ($address): string
  • Parameter name of parameter #2 changed: $errcode to $error_code
  • Parameter default value added for position #2 ($error_code): null
  • Parameter name of parameter #3 changed: $errstring to $error_message
  • Parameter default value added for position #3 ($error_message): null
  • Parameter type added for parameter #4 ($flags): int
  • Parameter default value added for position #4 ($flags): STREAM_SERVER_BIND | STREAM_SERVER_LISTEN
  • Parameter default value added for position #5 ($context): null
  stream_socket_server(
-     $localaddress,
+     string $address,
-     &$errcode,
+     &$error_code = null,
-     &$errstring,
+     &$error_message = null,
-     $flags,
+     int $flags = STREAM_SERVER_BIND | STREAM_SERVER_LISTEN,
-     $context
+     $context = null
    )

stream_socket_server 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