3v4l.org

run code in 300+ PHP versions simultaneously
<?php function tftp_fetch($host, $filename) { $socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); // create the request packet $packet = chr(0) . chr(1) . $filename . chr(0) . 'octet' . chr(0); // UDP is connectionless, so we just send on it. socket_sendto($socket, $packet, strlen($packet), 0x100, $host, 69); $buffer = ''; $port = ''; $ret = ''; do { // $buffer and $port both come back with information for the ack // 516 = 4 bytes for the header + 512 bytes of data socket_recvfrom($socket, $buffer, 516, 0, $host, $port); // add the block number from the data packet to the ack packet $packet = chr(0) . chr(4) . substr($buffer, 2, 2); // send ack socket_sendto($socket, $packet, strlen($packet), 0, $host, $port); // append the data to the return variable // for large files this function should take a file handle as an arg $ret .= substr($buffer, 4); } while(strlen($buffer) == 516); // the first non-full packet is the last. return $ret; }
Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9, 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.0 - 5.4.45, 5.5.0 - 5.5.35, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.12 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.7

preferences:
220.6 ms | 406 KiB | 347 Q