3v4l.org

run code in 300+ PHP versions simultaneously
<?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 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Array and string offset access syntax with curly braces is no longer supported in /in/FhMvg on line 7
Process exited with code 255.
Output for 7.4.0 - 7.4.33
Deprecated: Array and string offset access syntax with curly braces is deprecated in /in/FhMvg on line 7 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 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33
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.0 - 5.4.27, 5.4.34 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 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.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.28 - 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.3.11, 4.4.0 - 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.

preferences:
256.93 ms | 401 KiB | 360 Q