3v4l.org

run code in 300+ PHP versions simultaneously
<?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 />"; } if (socket_bind($sock, $address, $port) === false) { echo "socket_bind() failed: reason: " . socket_strerror(socket_last_error($sock)) . "\n"; }else { echo "bind 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 />"; ?>
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 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.4, 8.3.6
<h2>TCP/IP Connection</h2><br /> Fatal error: Uncaught Error: Call to undefined function socket_create() in /in/1cafo:17 Stack trace: #0 {main} thrown in /in/1cafo on line 17
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 <h2>TCP/IP Connection</h2><br /> Fatal error: Uncaught Error: Call to undefined function socket_create() in /in/1cafo:17 Stack trace: #0 {main} thrown in /in/1cafo on line 17
Process exited with code 255.
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
<h2>TCP/IP Connection</h2><br /> Fatal error: Call to undefined function socket_create() in /in/1cafo on line 17
Process exited with code 255.
Output for 5.0.4 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
<h2>TCP/IP Connection</h2><br />OK.<br /> Notice: Undefined variable: sock in /in/1cafo on line 23 Notice: Undefined variable: port in /in/1cafo on line 23 Warning: socket_bind() expects parameter 1 to be resource, null given in /in/1cafo on line 23 bind 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/1cafo on line 30 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/1cafo on line 43 OK.<br />Closing socket...OK.<br /><br />
Output for 5.0.0 - 5.0.3
<h2>TCP/IP Connection</h2><br />OK.<br /> Notice: Undefined variable: sock in /in/1cafo on line 23 Notice: Undefined variable: port in /in/1cafo on line 23 Warning: socket_bind() expects parameter 1 to be resource, null given in /in/1cafo on line 23 bind 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/1cafo on line 30 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/1cafo on line 43 OK.<br />Closing socket...OK.<br /><br />
Output for 4.3.2 - 4.3.11, 4.4.0 - 4.4.9
<h2>TCP/IP Connection</h2><br />OK.<br /> Notice: Undefined variable: sock in /in/1cafo on line 23 Notice: Undefined variable: port in /in/1cafo on line 23 Warning: socket_bind() expects parameter 1 to be resource, null given in /in/1cafo on line 23 bind 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/1cafo on line 30 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/1cafo on line 43 OK.<br />Closing socket...OK.<br /><br />
Output for 4.3.0 - 4.3.1
<h2>TCP/IP Connection</h2><br />OK.<br /> Notice: Undefined variable: sock in /in/1cafo on line 23 Notice: Undefined variable: port in /in/1cafo on line 23 Warning: socket_bind() expects parameter 1 to be resource, null given in /in/1cafo on line 23 bind OK.<br />Attempting to connect to 'ppp089210193030.access.hol.gr' on port '11000'...
Process exited with code 139.

preferences:
316.64 ms | 401 KiB | 458 Q