PHP - Sockets

From LXF Wiki

Practical PHP Programming

(Original version written by Paul Hudson for Linux Format magazine issue 47.)


Sockets are good for all sorts of things beyond just connecting the iron into. Want to revolutionise your PHP scripts? We plug you in...


Files are files, directories are files, and devices are files. Everything, and, conversely nothing (think /dev/null), is a file. So it should come as no surprise to you that sockets are files also, and the logical extension of that fact is that you can manipulate files and sockets in precisely the same way.

But first, let me explain what a socket actually is. Perhaps the best way to think of a socket is like a connector, and might be between a program and a port, or perhaps two programs - data goes in one end, and comes out the other end. There's a lot more to sockets beyond that, but it's not important on the whole - at least not for this instalment.