phpstack - A TCP/IP Stack and Web Server in PHP
Adam Dunkels writes "Following the
trend of writing 'inappropriate' programs in the PHP scripting language, I have written a small TCP/IP stack and a web server entirely in PHP. It is extremely stripped down: the IP stack only implements the most basic functionality required for running the web server and the web server cannot handle pages larger than 1.5k. Nevertheless, the stack is able to support an unlimited number of simultaneous TCP connections and the web server has support for PHP scripting. A live demonstration server is up and running the phpstack software."
... the web server cannot handle pages larger than 1.5k
:-)
Uhh, I guess that's one way to survive a slashdotting.
But, seriously, your demo doesn't even parse URLs; it is just hard-coded to send out a pre-written response on different ports:
http://193.10.67.151:8080/ -- Main page
http://193.10.67.151:8081/ -- Picture of a computer
http://193.10.67.151:8082/ -- PHP Powered logo
http://193.10.67.151:8083/ -- Picture of some code
http://193.10.67.151:8084/ -- Stats
Combined with the 1.5KB limit, that seems rather half-baked to me.
You are basically reading just enough of the TCP/IP info to get the source IP address and port, running a different script depending on which port, then packaging the output into a single TCP/IP packet destined for that IP address and sending them out over the network.
I am rather sure the 1.5KB limit is because you didn't figure out how to deal with packet fragments, for example. So there's no way to raise that limit without rewriting the TCP/IP code. Not cool.
I gotta see this... and low and behold it looks sllooooow but it came through.
btw content below:
The phpstack demo server
Welcome to the phpstack demo server! phpstack is a small TCP/IP stack and web server written in PHP. It is a quick and dirty proof-of-concept hack and shouldn't be taken too seriously.
The web pages and pictures on this page are served by the phpstack server. The server only allows very small HTML pages and pictures, but it is able to support an unlimited amount of simultaneous connections.
Read more about the phpstack on its home page:
http://www.sics.se/~adam/phpstack/
You are visitor number 446 and your IP address is XX.XX.XX.XX.
Here's a screenshot of the phpserver results. Pretty cool stuff.
PHP has a CLI interpreter. You can run it just like you run perl or whatever.
http://nanoweb.si.kz/
:
... and a lot more
Nanoweb is an HTTP server written in PHP, designed to be small, secure, and extensible.
It is distributed under the terms of the GNU General Public License.
Nanoweb's main features are
- HTTP/1.1 compliance
- Powerful and easy configuration
- Modular architecture
- FastCGI, CGI and Server side includes support
- Name and port based virtual hosts
- Access control lists
- htpasswd, MySQL, PostgreSQL and LDAP authentication support
- Themes for server generated content
- Apache compatible log format, MySQL logging
- Directory browsing
- inetd support and SSL via external helpers
- Denial of Service protection
- Proxy Server extension
- Filters and gzip support
- RBL support (mail-abuse.org)
- Extension Protocols (request methods) support
-
lone, dfx.
It's just really slow. I'm visitor 1853.
It's not offtopic, dumbass. It's orthogonal.
There is now (since early 4.x versions) a command line version of PHP, for scripting purposes. All the benifits of mod_php in your scripts, and it is now installed by default along side the apache module. You can also acheive a similiar solution using the cgi binary.
PHP does not depend on a webserver to run. It can be executed standalone just fine. I use it that way as a PERL replacement. No need for flame wars, I do still use PERL , the PHP stuff is for "backend" scripts on my webservers that share some common custom PHP libraries I have written as part of web applications, in so doing I eliminated the need to reimplement a lot of logic in PERL...Anyway that was off topic, the point is PHP does NOT need a webserver to run.
MS2k
This guy is the greatest! its slow as crap, but its not down.
Please, please, please read the the code (or at least the announcement) before replying. You are totally off the mark here. In short: It's easy to create a webserver in PHP (everybody did it so I did too: http://ter.dk:4281/ ), but we are talking about a TCP/IP-stack as well.
And please, please, please don't mark any post "Informative", just because it is shorter than the original announcement.
In response to a lot of other bewildered posts:
Okay, get ready for the explanation of the announcement: PHP is just relying on the underneath TCP/IP-stack. Adams example includes the TCP/IP-stack itself (including ICMP). That's pretty neat.
- Peter Brodersen; professional nerd
I am the author of this and I must point out that the phpstack server is actually still running after over two hours of slashdotting! It is extremely slow, however, because of the insane amount of IP packets that have to traverse the 115200 bps serial line that connects the server with the rest of the world. The front page of the server currently reports that it has served 13157 visitors.
:-). The web server running on top of the stack is
really simple and can be seen as the equivalent of the "netcat"
web server someone suggested.
:-)
:-)
A lot of people that comment here focus solely on the web server part of this software and completely miss the novel part in this: the TCP/IP stack. Writing a simple web server is dead easy. To the best of my knowledge, however, nobody has been stupid enough to write a TCP/IP stack in PHP before
The TCP/IP stack is intensionally extremely simplified (or "half-baked", if you wish) and tailored to the specific needs of the simple web server. Someone implied that the reason for the simplifications was that I maybe hadn't "figured out" how to handle fragmented packets. Well, it does not have to do with packet fragmentation (IP fragmentation is not that much of an issue today), but with the TCP receiver not trying to put together incoming TCP segments into a stream. Interested people could take a look at my uIP or lwIP TCP/IP stacks to see how to solve these problems in the general case. I have also written a paper that discuss issues with reducing TCP and IP in more detail.
Of course, there are also the standard "this guy should get a life" comments. I always find it amusing to see such comments being posted only 10 minutes after the article hit the Slashdot front page, on a Saturday. I'm not the only one in need of a life, it seems
Finally, all of this is just a quick hack made solely for fun (and in part to learn more about PHP). I submitted it to Slashdot simply because I enjoy seeing articles like this myself. From the insane amount of traffic to my demo server, it seems that quite a lot of other people find it interesting as well
I was # 20526, not bad, I even checked the server statics. Of course it only seems to show up those two pages.
The grass is only greener, if you don't take care of your own lawn.
I really can't see any real world application of such a, umm, toy. Also, the claim that "the stack is able to support an unlimited number of simultaneous TCP connections" is, well, bogus.
First off, regardless of how good a TCP/IP stack is you will still be limited by hardware. Then we have sockets, usually a 32 bit value on most platforms. Each client connection will use at least 1 of these sockets...and I'm guessing this "stack" uses PHP's socket functions; which wrap the real socket subsystem of the platform. So, that limits you to a maximun of 2^32 (~4294967296) available sockets; and 2^31 (~2147483648) on platforms that use a signed integer type to represent the socket. So, that little PHP toy stack will run outta sockets at some point.
Dreams are nice though aren't they? Anyways, hope your ass doesn't get DOS'ed too bad there! =P