3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php /* * PHP Sockets - How to create a TCP/IP socket client */ echo "<h2>TCP/IP Connection</h2><br />"; /* Get the port for the WWW service. */ $service_port = 11000; /* Get the IP address for the target host. */ $address = gethostbyname('ppp089210193030.access.hol.gr'); /* Create a TCP/IP socket. */ $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); if ($socket === false) { echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "<br />"; } else { echo "OK.<br />"; } echo "Attempting to connect to '$address' on port '$service_port'..."; $result = socket_connect($socket, $address, $service_port); if ($result === false) { echo "socket_connect() failed.<br />Reason: ($result) " . socket_strerror(socket_last_error($socket)) . "<br />"; } else { echo "OK.<br />"; } $in = "HEAD / HTTP/1.1<br />"; $in .= "Host: www.example.com<br />"; $in .= "Connection: Close<br /><br />"; $out = ''; echo $in; echo "Sending HTTP HEAD request..."; socket_write($socket, $in, strlen($in)); echo "OK.<br />"; /* echo "Reading response:<br /><br />"; while ($out = socket_read($socket, 2048)) { echo $out."<br /><br />"; } */ echo "Closing socket..."; socket_close($socket); echo "OK.<br /><br />"; ?>
based on 1cafo
Output for 7.0.0 - 7.2.0
<h2>TCP/IP Connection</h2><br /> Fatal error: Uncaught Error: Call to undefined function socket_create() in /in/9jNR0:17 Stack trace: #0 {main} thrown in /in/9jNR0 on line 17
Process exited with code 255.
Output for 5.4.2 - 5.6.28
<h2>TCP/IP Connection</h2><br /> Fatal error: Call to undefined function socket_create() in /in/9jNR0 on line 17
Process exited with code 255.
Output for 5.3.18 - 5.3.29
<h2>TCP/IP Connection</h2><br />OK.<br />Attempting to connect to 'ppp089210193030.access.hol.gr' on port '11000'... Warning: socket_connect(): Host lookup failed [-10002]: Host name lookup failure in /in/9jNR0 on line 25 socket_connect() failed.<br />Reason: () Host name lookup failure<br />HEAD / HTTP/1.1<br />Host: www.example.com<br />Connection: Close<br /><br />Sending HTTP HEAD request... Warning: socket_write(): unable to write to socket [32]: Broken pipe in /in/9jNR0 on line 38 OK.<br />Closing socket...OK.<br /><br />