In PHP, stream_get_transports() returns the names of the socket transports available in the current PHP build, such as tcp, udp, and unix.
Transports are the network protocols you can use with stream_socket_client(), stream_socket_server(), and related socket stream functions. The list depends on the operating system and how PHP was compiled.
Syntax
Call stream_get_transports() with the values you need. Start with this line.
PHP
$transports = stream_get_transports();
Call
What it does
stream_get_transports()
Returns an array of transport name strings.
in_array("tcp", stream_get_transports())
Checks whether the TCP transport is available.
in_array("udp", stream_get_transports())
Checks whether the UDP transport is available.
Tutorial demos check for common names instead of dumping the full array, so the printed output stays the same on most machines.
Library declarations
PHP
stream_get_transports(): array
Parameters
Parameter
Description
—
This function takes no parameters.
Return Value
Return Value
Description
array
Indexed array of transport names (for example "tcp", "udp", "ssl", "unix").
PHP Examples
Example 1 — Check for TCP and UDP
Ask whether the two most common internet transports are registered.