PHP | getservbyname() Function Last Updated : 30 Aug, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report The getservbyname() function is an inbuilt function in PHP which returns the port number for given protocol and Internet service. Syntax: int getservbyname( string $service, string $protocol ) Parameters: This function accepts two parameters as mentioned above and described below: $protocol: It is required parameter. It specifies protocol name, like tcp, udp etc in string format. $service: It is required parameter. It specifies the Internet service name, like http int string format. Return Value: This function returns the port number on success or False if service or protocol not found. Note: This function is available for PHP 4.0.0 and newer version. Below programs illustrate the getservbyname() function in PHP: Program 1: php <?php // Use getservbyname() function to get // port number associated with an // Internet service and protocol $portnum = getservbyname("http", "tcp"); // Display the result echo $portnum; ?> Output: 80 Program 2: This program checks multiple services. php <?php // Create an array of services $services = array("ftp", "ssh", "telnet", "http", "https"); // Loop run for each services foreach( $services as $index) { // Use getservbyname() function to get // the port number associated with an // Internet service and protocol echo getservbyname($index, "tcp") . ": " . $index . "<br>"; } ?> Output: 21: ftp 22: ssh 23: telnet 80: http 443: https Reference: https://www.php.net/manual/en/function.getservbyname.php Comment More infoAdvertise with us Next Article PHP | getservbyport() Function G gekcho Follow Improve Article Tags : Web Technologies PHP PHP-function Similar Reads PHP | getprotobyname() Function The getprotobyname() function is an inbuilt function in PHP which returns the protocol number for a specified protocol name. Syntax: int getprotobyname( string $name ) Parameters: This function accepts single parameter $name which is required. It specifies the protocol name, like tcp, icmp, udp, ip 1 min read PHP | getservbyport() Function The getservbyport() function is an inbuilt function in PHP which returns the Internet service for given protocol and port number. Syntax: string getservbyport( int $port, string $protocol) Parameters: This function accepts two parameters as mentioned above and described below: $protocol: It is requi 1 min read PHP getrusage() Function The getrusage() function is an inbuilt function in PHP that returns current resource usage. Syntax: getrusage(int $mode = 0)Parameters: This function has only one parameter: $mode: This parameter will be called with RUSAGE_CHILDREN, if the mode will be 1.Return Value: This function returns an assoc 1 min read PHP gettype() Function The PHP gettype() function returns the type of a variable as a string. It identifies the variable's data type, such as string, integer, array, boolean, etc., allowing developers to check and handle different data types dynamically.Syntax:string gettype ( $var )Parameter: This function accepts a sing 2 min read PHP ob_get_level() Function The ob_get_level() function is an inbuilt function in PHP that is used to get the current output buffer level in a nested level. Output buffering is a feature in PHP that allows you to capture and manipulate output before it is sent to the browser or client. Syntaxob_get_level(): intParameter This f 2 min read PHP | imagesy() Function The imagesy() function is an inbuilt function in PHP which is used to return the height of the given image. Syntax: int imagesy( $image ) Parameters: This function accepts single parameters $image which is mandatory. This $image variable store the image created by imagecreatetruecolor() image creati 1 min read Like