PHP Servers

Looking for something new to play with in your journey to become a PHP guru (like me)? Try writing servers! Start off by looking at the socket_create() function and then once you got the hang of that, look into the Server tree of objects in the PEAR repository.

By using Server/HTTP, you can make your own web server with just a couple of lines of code:

require(’HTTP/Server.php’);
$ws = new HTTP_Server(’127.0.0.1′,’80′, ‘Sequential’);
$ws->start();

You can then point your web browser at http://localhost:80/ and it will serve you pages - blank pages, but pages nonetheless. You can extend the HTTP class to handle your GET/POST (etc) requests. I wrote a webserver that would render a POVRay scene on demand with a URL like http://localhost/pov/filename.pov/800/600/

The coolest thing is that because you handle the GET requests yourself (i.e., you have to parse them and do something useful with them), you determine exactly what happens.

This way of using PHP interests me so much that I’m thinking about writing a bit of a servery suite for doing useful stuff (pretty intriguing, eh … NOT!)

Leave a comment

Your comment