Wednesday, October 8, 2025
HomeLanguagesPHP | stream_get_transports() Function

PHP | stream_get_transports() Function

The stream_get_transports() function is an inbuilt function in PHP which is used to get the list of registered socket transports. This function returns the indexed array containing the name of all available socket.

Syntax:

array stream_get_transports( void )

Parameters: This function does not accept any parameter.

Return Value: This function returns an array containing the name of all available socket transport.

Below programs illustrate the stream_get_transports() function in PHP:

Program 1:




<?php
  
// PHP program to illustrate
// stream_get_transports function
  
print_r(stream_get_transports());
?>


Output:

Array
(
    [0] => tcp
    [1] => udp
    [2] => unix
    [3] => udg
    [4] => ssl
    [5] => tls
    [6] => tlsv1.0
    [7] => tlsv1.1
    [8] => tlsv1.2
)

Program 2: Program to check transports are available or not.




<?php
  
// PHP program to illustrate
// stream_get_transports function
  
$wrapper = array (
    'tcp',
    'unix',
    'file',
    'ssl',
    'GFG'
);
  
// Checking socket transport enabled or not
foreach ($wrapper as &$gfg) {
    if (in_array($gfg, stream_get_transports())) {
        echo $gfg . ': Enabled' . "\n";
    } else {
        echo $gfg . ": Not Enabled" . "\n";
    }
}
  
?>


Output:

tcp: Enabled
unix: Enabled
file: Not Enabled
ssl: Enabled
GFG: Not Enabled

Reference: http://php.net/manual/en/function.stream-get-transports.php

RELATED ARTICLES

Most Popular

Dominic
32342 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6712 POSTS0 COMMENTS
Nicole Veronica
11875 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11937 POSTS0 COMMENTS
Shaida Kate Naidoo
6833 POSTS0 COMMENTS
Ted Musemwa
7092 POSTS0 COMMENTS
Thapelo Manthata
6786 POSTS0 COMMENTS
Umr Jansen
6789 POSTS0 COMMENTS