at 2007-06-28
in Experiments
by friebe
(0 comments)
There's already been a couple of people out there implementing a web server in userland PHP. From my point of view, people are doing this for fun, or as proof-of-concept, and those experiments usually tend to fade out of sight and disappear from public interest - so my guess is that they're not seriously being used.
At 1&1, we actually have such software running in PHP - multiple instances of FTP daemons which serve the purpose of attaching functionality to uploaded files (when an image is uploaded in this directory, update the underlying database), an application server called "Peking" that stores when a customer care agent has opened a customer's contract, and a real-time-logger that stores extracts of Windows Media Server logfiles transmitted via network into a MySQL database for billing reasons. All of these process thousands of requests every day and handle database and LDAP failures gracefully, and all of them have stable memory usage.
As a word for all disbelievers, daemons in PHP are possible!
To demonstrate how this works with the XP framework, I've written a web server implementation using the peer.server package.
Overview You can start it as follows: xp/trunk/experiments/arena/httpservice$ xpcli HttpService
You should then see:
---> Using server model peer.server.Server ---> Binding 127.0.0.1:80 ===> Server started
To see it in action, open your favorite webbrowser and point it to http://localhost/planet/home.html and you will see the XP framework's new homepage appearing.
Internals The parsing and interpretation of on-the-wire-data is performed in the HttpProtocol class' handleData() method. It takes care of request line and header parsing and the hands over control to a so-called "url handler", which is determined by pattern matching on the request URL.
The only handler installed in the SVN version is the FileHandler which takes care of serving static content, that is, it passes through files beyond the document root given to its constructor. The one advanced feature it supports is that it will react to the If-Modified-Since header and yield a HTTP 304 Not modified in case the file is untouched, thus greatly improving performance.
Want to have a look inside? Here's the sourecode.
Interested in trying it out? Grab yourself an anonymous SVN checkout (svn co svn://php3.de/xp/trunk), set up PHP's include path to contain the checked-out-directory skeleton, cd into the experiments/arena/httpservice path and type the afforementioned command.
Note: You may encounter problems on Un*x systems if you are not logged on as root, use 8080 as bind port instead by supplying -p 8080 as argument to HttpService
|
Subscribe
You can subscribe to the XP framework's news by using RSS syndication.
CategoriesNews General PHP5 Announcements RFCs Further reading Examples Editorial EASC Experiments Unittests Databases
RelatedFind related articles by a search for «HttpService».
|