3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<? $address=$_SERVER['REMOTE_ADDR']; if (isset($_REQUEST['port']) and (!strlen($_REQUEST['port'])==0)) $port=$_REQUEST['port']; else unset($port); if (isset($port) and ($socket=socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) and (socket_connect($socket, $address, $port))) { $text="Connection successful on IP $address, port $port"; socket_close($socket); } else $text="Unable to connect<pre>".socket_strerror(socket_last_error())."</pre>"; echo "<html><head></head><body>". $text. "</body></html>"; ?>
based on p9RU3
Output for 7.0.0 - 7.2.0
Notice: Undefined index: REMOTE_ADDR in /in/JDveU on line 2 Fatal error: Uncaught Error: Call to undefined function socket_strerror() in /in/JDveU:18 Stack trace: #0 {main} thrown in /in/JDveU on line 18
Process exited with code 255.
Output for 5.4.12 - 5.6.28
Notice: Undefined index: REMOTE_ADDR in /in/JDveU on line 2 Fatal error: Call to undefined function socket_strerror() in /in/JDveU on line 18
Process exited with code 255.
Output for 5.3.22 - 5.3.29
<? $address=$_SERVER['REMOTE_ADDR']; if (isset($_REQUEST['port']) and (!strlen($_REQUEST['port'])==0)) $port=$_REQUEST['port']; else unset($port); if (isset($port) and ($socket=socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) and (socket_connect($socket, $address, $port))) { $text="Connection successful on IP $address, port $port"; socket_close($socket); } else $text="Unable to connect<pre>".socket_strerror(socket_last_error())."</pre>"; echo "<html><head></head><body>". $text. "</body></html>"; ?>