stream_socket_client

FunctionParams changed in PHP 8.0

Open Internet or Unix domain socket connection.

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_client Function synopsis

stream_socket_client(
    string $address,
    &$error_code = null,
    &$error_message = null,
    ?float $timeout = null,
    int $flags = STREAM_CLIENT_CONNECT,
    $context = null
  )

Parameters

$address

Typestring

Address to the socket to connect to.

$error_code

Passed by reference, OptionalDefault valuenull

Will be set to the system level error number if connection fails.

$error_message

Passed by reference, OptionalDefault valuenull

Will be set to the system level error message if the connection fails.

$timeout

OptionalType?floatDefault valuenull

Number of seconds until the connect() system call should timeout. By default, default_socket_timeout is used.

$flags

OptionalTypeintDefault valueSTREAM_CLIENT_CONNECT

Bitmask field which may be set to any combination of connection flags. Currently the select of connection flags is limited to STREAM_CLIENT_CONNECT (default), STREAM_CLIENT_ASYNC_CONNECT and STREAM_CLIENT_PERSISTENT.

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

$context

OptionalDefault valuenull

A valid context resource created with stream_context_create.

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_client Function

PHP 8.0

  • Parameter name of parameter #1 changed: $remoteaddress 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 ($timeout): ?float
  • Parameter default value added for position #4 ($timeout): null
  • Parameter type added for parameter #5 ($flags): int
  • Parameter default value added for position #5 ($flags): STREAM_CLIENT_CONNECT
  • Parameter default value added for position #6 ($context): null
  stream_socket_client(
-     $remoteaddress,
+     string $address,
-     &$errcode,
+     &$error_code = null,
-     &$errstring,
+     &$error_message = null,
-     $timeout,
+     ?float $timeout = null,
-     $flags,
+     int $flags = STREAM_CLIENT_CONNECT,
-     $context
+     $context = null
    )

stream_socket_client 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