getservbyname

mixed getservbyname(string service_name, string protocol_type) 
service_name Service name
protocol_type Protocol name; either tcp or udp

Gets the port number for a service.

Returns:

Port number; FALSE on error

Description:

getservbyname() fetches the port number for the given service running under the given protocol, as defined in your system’s /etc/services or c:\windows\services file. If the protocol is not recognized, the function returns FALSE.

Availability:

UNIX, Windows

Version:

4.0b4+

See also:

getservbyport() 

Example:

23.11. Find the HTTP service’s default listening port
 <?php $protocol = 'tcp'; $service = 'http'; echo "The $service service listens on port ", getservbyname($service, $protocol), ' by default.'; ?> ...

Get PHP Functions Essential Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.