stream_socket_sendto()

stream_socket_sendto() — Sends a message to a socket, whether it is connected or not.

Built-in function of PHP 8.5. The manual lists it as available in PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

Signature

stream_socket_sendto(resource $socket, string $data, int $flags = 0, string $address = ""): int|false

Parameters

ParameterTypeWhat it takes
$socketresourceThe socket to send data to.
$datastringThe data to be sent.
$flagsintThe value of flags can be any combination of the following: possible values for flags STREAM_OOB Process OOB (out-of-band) data.
$addressstringThe address specified when the socket stream was created will be used unless an alternate address is specified in address.

Return value

Returns a result code, as an integer, or false on failure.

Example

A runnable snippet:

/* Open a socket to port 1234 on localhost */ $socket = stream_socket_client('tcp://127.0.0.1:1234'); /* Send ordinary data via ordinary channels. */ fwrite($socket, "Normal data transmit."); /* Send more data out of band. */ stream_socket_sendto($socket, "Out of Band data.", STREAM_OOB); /* Close it up */ fclose($socket);

See also

stream_socket_recvfrom(), stream_socket_client(), stream_socket_server()

All PHP 8.5 built-in functions

Reference card built from the PHP manual page stream_socket_sendto() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.