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:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


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.

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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";
    }
}
  
?>

chevron_right


Output:

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

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



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.