getprotobyname()
getprotobyname() — Get protocol number associated with protocol name.
Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
getprotobyname() returns the protocol number associated with the protocol protocol as per /etc/protocols.
Signature
getprotobyname(string $protocol): int|false
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $protocol | string | The protocol name. |
Return value
Returns the protocol number, or false on failure.
Example
A runnable snippet:
$protocol = 'tcp'; $get_prot = getprotobyname($protocol); if ($get_prot === FALSE) { echo 'Invalid Protocol'; } else { echo 'Protocol #' . $get_prot; }
See also
All PHP 8.5 built-in functions
Reference card built from the PHP manual page getprotobyname() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.