getservbyname
(PHP 4, PHP 5, PHP 7, PHP 8)
getservbyname — 獲取網際網路服務協議對應的埠
說明
getservbyname(string
$service
, string $protocol
): int
getservbyname()
返回網際網路服務 service
指定的協議 protocol
中對應的埠,
依據 /etc/services。
參數
-
service
-
網際網路服務名稱的字串。
-
protocol
-
protocol
既可以是"tcp"
也可以是"udp"
(小寫)。
返回值
返回埠號,如果 service
或 protocol
未找到返回 false
。
範例
示例 #1 getservbyname() 例子
<?php
$services = array('http', 'ftp', 'ssh', 'telnet', 'imap',
'smtp', 'nicname', 'gopher', 'finger', 'pop3', 'www');
foreach ($services as $service) {
$port = getservbyname($service, 'tcp');
echo $service . ": " . $port . "<br />\n";
}
?>
參見
- getservbyport() - Get Internet service which corresponds to port and protocol
- » http://www.iana.org/assignments/port-numbers 埠號的完整列表