PHP getservbyport() Function
The PHP getservbyport() function returns the Internet service associated with an specified port for the specified protocol. The function returns on failure.
Syntax
getservbyport(port, protocol)
Parameters
port |
Required. Specify the port number. |
protocol |
Required. Specify protocol which is either "tcp" or "udp" (in lowercase). |
Return Value
Returns the Internet service name as a string, or false on failure.
Example:
The example below shows the usage of getservbyport() function.
<?php //array containing the port numbers $ports = array(80, 21, 22, 23, 143, 25, 110); //finding the Internet service associated with //above port numbers for "tcp" protocol foreach ($ports as $port) { $service = getservbyport($port, 'tcp'); echo $port .": " . $service . "\n"; } ?>
The output of the above code will be:
80: http 21: ftp 22: ssh 23: telnet 143: imap2 25: smtp 110: pop3
❮ PHP Network Reference