(PHP 4, PHP 5, PHP 7, PHP 8)
getservbyname — 獲取互聯(lián)網(wǎng)服務(wù)協(xié)議對(duì)應(yīng)的端口
$service, string $protocol): int
getservbyname()
返回互聯(lián)網(wǎng)服務(wù) service 指定的協(xié)議 protocol 中對(duì)應(yīng)的端口,
依據(jù) /etc/services。
service互聯(lián)網(wǎng)服務(wù)名稱的字符串。
protocol
protocol 既可以是 "tcp"
也可以是 "udp" (小寫)。
返回端口號(hào),如果 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";
}
?>