getservbyname
Description
The getservbyname of Network for PHP get port number associated with an Internet service and protocol.
Syntax
getservbyname( string $service, string $protocol ): int|false
Parameters
service
The Internet service name, as a string.
protocol
protocol is either "tcp" or "udp" (in lowercase).
Return
Returns the port number, or false if service or protocol is not found.
Examples
1 · service protocol
<? $service = 'http'; $protocol = 'tcp'; $return = getservbyname($service, $protocol); echo $return;
80
2
<? $array = array('finger', 'ftp', 'gopher', 'http', 'imap', 'nicname', 'pop3', 'smtp', 'ssh', 'telnet', 'www'); $protocol = 'tcp'; foreach($array as $service) { $return = getservbyname($service, $protocol); echo "$service: $return\n"; }
finger: 79 ftp: 21 gopher: 70 http: 80 imap: 143 nicname: 43 pop3: 110 smtp: 25 ssh: 22 telnet: 23 www: 80
Links
Network
- checkdnsrr
- closelog
- dns_check_record
- dns_get_mx
- dns_get_record
- fsockopen
- gethostbyaddr
- gethostbyname
- gethostbynamel
- gethostname
- getmxrr
- getprotobyname
- getprotobynumber
- getservbyport
- header
- header_register_callback
- header_remove
- headers_list
- headers_sent
- http_response_code
- inet_ntop
- inet_pton
- ip2long
- long2ip
- openlog
- pfsockopen
- setcookie
- setrawcookie
- socket_get_status
- socket_set_blocking
- socket_set_timeout
- syslog