CakeFest 2024: The Official CakePHP Conference

getservbyname

(PHP 4, PHP 5, PHP 7, PHP 8)

getservbyname获取互联网服务协议对应的端口

说明

getservbyname(string $service, string $protocol): int|false

getservbyname() 返回互联网服务 service 指定的协议 protocol 中对应的端口, 依据 /etc/services

参数

service

互联网服务名称的字符串。

protocol

protocol 既可以是 "tcp" 也可以是 "udp" (小写)。

返回值

返回端口号,如果 serviceprotocol 未找到返回 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";
}
?>

参见

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top