3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $str = "?announce=[-tg-station] thingy opened fart&key=this_is_a_test_key"; $port = 7812; $addr = "94.21.30.22"; // All queries must begin with a question mark (ie "?players") if($str{0} != '?') $str = ('?' . $str); /* --- Prepare a packet to send to the server (based on a reverse-engineered packet structure) --- */ $query = "\x00\x83" . pack('n', strlen($str) + 6) . "\x00\x00\x00\x00\x00" . $str . "\x00"; /* --- Create a socket and connect it to the server --- */ $server = socket_create(AF_INET,SOCK_STREAM,SOL_TCP) or die('Unable to create export socket.'); if(!socket_connect($server,$addr,$port)) { return "ERROR"; } /* --- Send bytes to the server. Loop until all bytes have been sent --- */ $bytestosend = strlen($query); $bytessent = 0; while ($bytessent < $bytestosend) { //echo $bytessent.'<br>'; $result = socket_write($server,substr($query,$bytessent),$bytestosend-$bytessent); //echo 'Sent '.$result.' bytes<br>'; if ($result===FALSE) die(socket_strerror(socket_last_error())); $bytessent += $result; } /* --- Idle for a while until recieved bytes from game server --- */ $result = socket_read($server, 10000, PHP_BINARY_READ); socket_close($server); // we don't need this anymore ?>
Output for 7.0.0 - 7.1.0
Fatal error: Uncaught Error: Call to undefined function socket_create() in /in/FhMvg:13 Stack trace: #0 {main} thrown in /in/FhMvg on line 13
Process exited with code 255.
Output for 5.4.34 - 5.6.28
Fatal error: Call to undefined function socket_create() in /in/FhMvg on line 13
Process exited with code 255.
Output for 5.0.0 - 5.4.32
Warning: socket_connect(): unable to connect [101]: Network is unreachable in /in/FhMvg on line 14
Output for 4.3.2 - 4.4.9
Warning: socket_connect() unable to connect [101]: Network is unreachable in /in/FhMvg on line 14
Output for 4.3.0 - 4.3.1

Process exited with code 139.