How to create socket in php

A socket connection can be created in php using the code snippet below. This code snippet also shows how to write into a socket and read from a socket using php.

$SERVER_IP = 'x.x.x.x';
$SERVER_PORT = 'yy';
$Server = socket_create(AF_INET, $SOCK_STREAM, $SOL_TCP);
if($ServerConnected = @socket_connect($Server, $SERVER_IP, $SERVER_PORT))
@socket_write($Server , 'hello');
@socket_read($Server , 256);

Hope the information presented here is useful. Please leave your suggestions, feedback or queries in the comments section below…!!

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">