3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function isAlive($services) { foreach ($services as $address => $port) { $service = array( "address" => $address, "port" => $port, "errno" => "", "errstr" => "", "alive" => false ); $sock = @fsockopen($address, $port, $service["errno"], $service["errstr"], 5); if ($sock) { fprintf($sock, "GET / HTTP/1.0\r\n"); fprintf($sock, "\r\n"); $service["response"] = stream_get_contents($sock); if ($service["response"]) { $service["alive"] = true; } fclose($sock); } yield $service; } } $services = array( "php.net" => 80, "explain.so" => 80, "do1asdasdas.net" => 80 ); foreach (isAlive($services) as $service) { if (!$service["alive"]) { printf( "%s:%d: failure (%d) %s\n", $service["address"], $service["port"], $service["errno"], $service["errstr"]); } else { printf( "%s:%d: alive: %d bytes\n", $service["address"], $service["port"], strlen($service["response"])); } } ?>
Output for 5.5.0 - 7.1.0
php.net:80: failure (0) php_network_getaddresses: getaddrinfo failed: Name or service not known explain.so:80: failure (0) php_network_getaddresses: getaddrinfo failed: Name or service not known do1asdasdas.net:80: failure (0) php_network_getaddresses: getaddrinfo failed: Name or service not known
Output for 5.4.0 - 5.4.45
Parse error: syntax error, unexpected '$service' (T_VARIABLE) in /in/mMmXU on line 23
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected T_VARIABLE in /in/mMmXU on line 23
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_VARIABLE in /in/mMmXU on line 23
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/mMmXU on line 23
Process exited with code 255.