Example 1 — Print the Local Host Name
Call gethostname() and print the result. The output below is a typical sample name.
<?php
$name = gethostname();
if ($name === false) {
echo "Could not read host name", PHP_EOL;
} else {
echo $name, PHP_EOL;
} How It Works
- gethostname() asks the OS for the machine name.
- false means the name could not be read.
- Otherwise we print the string.
- "web-server-01" is sample output for the tutorial.

