phpstack - A TCP/IP Stack and Web Server in PHP 295
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."
Unlimited connections, really? (Score:5, Funny)
You shouldn't have said that here. We are about to brute test this 'unlimited amount of simultaneous connections' thing.
Re:Unlimited connections, really? (Score:5, Funny)
Re:Unlimited connections, really? (Score:3, Insightful)
Fairly slow, but still rather impressive.
Re:Unlimited connections, really? (Score:3, Interesting)
I was the visitor number 7532, and stiiilll goooiiinnggg!!!!
Gotta admit, i'm impressed :). Even if the pictures don't ... wait, they just loaded. All of them. From a server in the middle of a slashdotting. Implemented in a scripting language.
Now I'm impressed :).
Re:Unlimited connections, really? (Score:3, Interesting)
But I want to see them try doing this on a weekday at about 1pm EST =)
Re:Unlimited connections, really? (Score:3, Informative)
Re:Unlimited connections, really? (Score:5, Funny)
I believe that was his point (Why not have slashdot do your load testing..)
Re:Unlimited connections, really? (Score:5, Funny)
http://www.sics.se/~adam/phpstack/
You are visitor number 3241 and your IP address is"
thats part of the page I got.
That is a VERY limited system.... (Score:4, Informative)
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.
Re:That is a VERY limited system.... (Score:2, Funny)
Re:That is a VERY limited system.... (Score:2)
Re:That is a VERY limited system.... (Score:2)
At the risk of seeming to squash innovation, does this afford ammunition to the "no one fired for buying ___" community?
Fragmentation helps the Monolithic Scylla...
Re:That is a VERY limited system.... (Score:5, Insightful)
I once wrote a webserver for an industrial microcontroller using some obscure language called "optoscript". But at least I made sure that I only needed to connect to one port to access different pages.
This isn't just a webserver. (Score:2)
Re:That is a VERY limited system.... (Score:4, Informative)
this code is not meant to be taken too seriously, it is just a quick and dirty proof-of-concept hack written in about 3 hours.
could you do better?
Re:That is a VERY limited system.... (Score:5, Insightful)
Re:That is a VERY limited system.... (Score:2, Insightful)
Yes. First, since I know TCP/IP, I would have designed around the 1.5KB limit initially, by ensuring that TCP/IP could actually send out multiple packets on one connection, rather than just one. And, second, I certainly would have it parsing URLs, for example. After all, we're talking PHP here, which has much of the string processing capabilities of Perl (preg_match, for instance). It's not a difficult for a good programmer.
Re:That is a VERY limited system.... (Score:5, Insightful)
Well, it clearly says it's a PoC hack so why not cut this author some slack? To be perfectly honest, I think this is rather impressive in more than one way. Sure, this isn't exactly a novel idea but that wasn't the point. It clearly is a show of flexibility. Php wasn't designed with these kinds of applications in mind, yet it seems to handle this kind of stuff impressingly well.
Also, it testifies to the fact that thinking outside the box is a good thing. I mean, come on, what would you rather see yet another mail client or some cool project that makes you go "hmm, how come I never thought of this"?
thinking outside the box.. (Score:2)
the only thing that resembles a 'box', that i'm thinking inside of, is my house. i like to be inside it while i think; thank you very much.
Re:That is a VERY limited system.... (Score:2)
Re:That is a VERY limited system.... (Score:2, Interesting)
This is the kinda stuff programmers do all the time when they are bored or playing around or trying stuff out. I'm not surprised someone did it, I'm just surprised it was considered worth telling anyone about. It's about as newsworthy as posting your homework solutions
Re:That is a VERY limited system.... (Score:2, Informative)
Well, how about because how he tried to "trick" us into thinking it was a real webserver? Notice all the URLs on his site have fake pieces on the end to make them look like real URLs? http://193.10.67.151:8084/stats.php for instance. The stats.php bit is part of the deception.
In fact, his "web" server doesn't case WHAT data is sent to those ports, valid URL request or not. As soon as a single packet is sent to it, it sends its
Re:That is a VERY limited system.... (Score:3, Interesting)
So what if theres a page name being passed back. Compliance perhaps? Eh. Its a finishing touch or an unfinished feature.
Get over it! Its the TCP stack that makes this baby interesting.
Re:That is a VERY limited system.... (Score:2)
Re:That is a VERY limited system.... (Score:3, Insightful)
Before you call someone else's interesting project "half-baked" and point out that he "didn't figure out" things (implying that you, however, did), why don't you go post YOUR php-based TCP/IP stack and webserver that DOES deal with the issues you mentioned. Then, you can freely criticize his work as much as you'd like, pointing out the solutions instead of highlighting the problems.
Until then, you should consider keeping comments like
Re:That is a VERY limited system.... (Score:5, Interesting)
So, basically, you can ONLY critisize something if you managed to rip the idea and make your own..
Ever written an OS?
Wait. Have you ever written an automated bot to post slashdot comments? If no, then you must STFU, as you have not done it yourself..
Shesh..
Re:That is a VERY limited system.... (Score:2)
Re:That is a VERY limited system.... (Score:2)
My Karma has ben in tact for years now, with a user ID near 1000..
Re:That is a VERY limited system.... (Score:2)
But then, I'm impressed with myself just for knowing what "php" is an acronym for.
Ouch (Score:2, Interesting)
Re:Ouch (Score:5, Funny)
dammit, if I was only 2 users earlier...
Re:Ouch (Score:2)
You are visitor number 5143
That's not bad. Slow to load, but live!
Re: (Score:2)
Re:Ouch (Score:2)
the thing is, the server/stack basically just shoots back premade packets if you will(the 1.5kb limit is there for this design choice, no need to keep up connections and stuff).
Alright. (Score:5, Funny)
"whoa 2 comments and it's already slashdotted"
"whoa dude, shouldn't have let slashdot post your server!"
"Imagine a beowulf cluster of these guys"
And i'm sure you can figure out more Slashdotisms people *smirks*
Seems pretty cool at any rate
Re:Alright. (Score:2, Funny)
I'll rise to the challenge... (Score:2)
- WHY DOESN'T SLASHDOT MIRROR THIS PHP TCP/IP STACK AND SAVE THIS POOR BASTARD THE DEATH OF HIS SERVER?
1. Read
2. Write equally useless TCP/IP stack in PHP
3. Write lame webserver utilizing useless TCP/IP stack
4. ?????
-JT
Not forgetting ... has Linux been ported to it yet (Score:3, Funny)
Re:For the replies made on my post. (Score:2)
Better yet, make a 386 emulator using php. Then you don't need to port gcc to it to do something usefull ;).
"Advance one clock cycle" would be a cool text in button in a web form submit button - especially if it the form would show you the states of every register and optinally memory locations. It might be an actually usefull program, demonstrating the workings of a 386 compatible processor.
ouch... (Score:5, Funny)
To the tune of Queen:
Another one bytes the dust!
Re:ouch... (Score:5, Funny)
With apologies to the late F.M.
Php is a scripting language
not a layer three network stack
Ain't no way your server won't break
Unless you're sitting in a SONET node rack
Are you crazy? Are you certified
Your server is a molten heap
Through the floor the slag still drips
to the sound of the beep
Chorus:
Another one bytes the dust
Another one bytes the dust
And another one gone, and another one gone
Another one bytes the dust
Hey, I'm gonna slashdot you
Another one bytes the dust
How long till my router cacks
after a weekend slashdot bitch smack
I invested everything that I had
even wrote a custom ip stack
Are you crazy? Are you certified
Your server is a molten heap
Through the floor the slag still drips
to the sound of the beep
chorus
There are plenty of ways you can hurt a host
and bring it to its knees
you can heat em
you can drop em
you can install bad ram
and even try using Windows ME
But you're batshit, yes out of your tree
If you think your isp won't freak
Through the floor your server melts
To the sound of the beep
chorus
Re:ouch... (Score:2)
Re:ouch... (Score:2)
Proving yet again why I don't want to go to heaven; all the interesting people aren't there !
First thing that went through my mind (Score:3, Informative)
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.
Due to the anticipation of the /. effect . . . (Score:5, Informative)
Comment removed (Score:3, Funny)
How..? (Score:3, Interesting)
Is PHP able to be run standalone?
I thought it was parsed by a webserver module when accessed?
Re:How..? (Score:3, Informative)
Re:How..? (Score:3, Informative)
Re: (Score:2)
PSHTTPD - PostScript webserver (Score:5, Interesting)
Re:PSHTTPD - PostScript webserver (Score:2)
Re:PSHTTPD - PostScript webserver (Score:5, Funny)
Re:PSHTTPD - PostScript webserver (Score:2)
Very true. Only some languages are a bit more difficult than others. Still for real quick and dirty 1 page efforts NetCat makes a great webserver ;)
Re:PSHTTPD - PostScript webserver / 8088 webserver (Score:2)
As it happens I was discussing eznos.org's [eznos.org] webserver running on a 8088 earlier today [slashdot.org].
Nanoweb anyone ? (Score:4, Informative)
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.
Re:Nanoweb anyone ? (Score:4, Informative)
Yes, but not TCP/IP stack.
Re:Nanoweb anyone ? (Score:2)
Re:Nanoweb anyone ? (Score:5, Funny)
Yea, but does it support PHP?
... unlimited ... (Score:3, Insightful)
unlimited == not hard coded (Score:2)
Ben
inappropriate language (Score:2)
Re:inappropriate language (Score:2)
cool! (Score:2, Funny)
Why? (Score:4, Funny)
BTM
Re:Why? (Score:2)
In theory you could have been right, if you were writing in a compiled language: you convert everything into one string of machine instructions which can be optimized as a mass, rather than suffering some of the inefficiencies of a monolithic TCP and IP stack beneath your program that you can't optimize further. That sort of thing does actually happen on microcontrollers.
However, PHP is a scripting language, so those optimizations don't get made. What could take a
I understand... (Score:5, Funny)
netcat anyone? (Score:3, Interesting)
Re:netcat anyone? (Score:2)
Re:netcat anyone? (Score:2)
TCP/IP stack (Score:2)
And now ... (Score:2)
Fantastic! (Score:2)
Interesting (Score:5, Funny)
Don't laugh (Score:2)
Actually, I have seen this very idea in Perl--a CGI script or a mod_perl module using HTTP::Daemon [cpan.org] or raw IO::Socket::INET sockets to start a temporary http daemon listening on a random port for the purpose of serving graphics made on the fly embedded in a generated web page. Very good for statistics and charts so you can serve everything--HTML and graphics--with one instance of script/mo
still up after an hour (Score:2)
From the author (Score:5, Informative)
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 [www.sics.se] or lwIP [www.sics.se] TCP/IP stacks to see how to solve these problems in the general case. I have also written a paper [www.sics.se] 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
Why should you get to decide... (Score:2)
From the looks of things he's done some other deeper tcp/ip stuff before. Better doing that for three hours than sitting in front of the TV like a zombie or playing whatever the first person shooter de jour is.
People who go "why?" miss the whole point of a project like this, it's meant as a bit of a joke, a way to forget about the mundane world of work and just write a program...gasp...for fun.
Yes PHP has lousy garbage collection, mainly because its designed for s
On the topic of pointless accomplishments... (Score:5, Insightful)
Why you ask? Well, I'm frankly not sure I would have ever thought of this "accomplishment" again had I not read many of the responses to the PHP thing...
A friend of mine and I were having a little debate about how people sometimes do utterly pointless things with computers. We came to the conclusion that hackers in the generic "computer geek that likes to push the boundaries" sense of the word just like to see how far they can push things. They like to see what they can make these machines do that their designers never could have imagined them doing. This PHP thing is a good example of that, but applied to a language rather than hardware.
Not every project has to have a real purpose behind it. Sometimes just seeing if you can pull something off, no matter how stupid it might seem, is well worth it.
Oh yeah... my friend's "pointless" project? He wrote a web server on a Timex Sinclair 1000! He wired up an old C64 300 baud modem to the expansion port (so he couldn't use the 16k memory module at the same time), then dialed into his PC and used that as the network layer. IP requests to the web server were forwarded through the phone line, through the modem, and on to the Timex, which served up the pages. Everything was pre-loaded into memory from cassette when the server was started. To this day I don't know how he wrote the code to interface with the modem... I do know that he is an electrical engineering god and that he did have some external components added to the modem, but he told me, and I believe him, that the Timex was in fact controlling the modem. And you thought being limited to 1.5K per page with this PHP thing was crazy! Remember, the Timex had a GRAND TOTAL of 2K built-in! This to me is about as sick (and pointless!) as anything can get.
Needless to say, his project was far and away more pointless than mine
The answer of course is "because we could, but we weren't so sure at the start". And that is many times the only answer you need.
it had to be said (groan) (Score:2)
Oh wait
n/m
Re:I don't get it, really I don't (Score:2)
You can run php as a standalone executible, which then runs an ip stack.
Re:I don't get it, really I don't (Score:5, Informative)
MS2k
Re:I don't get it, really I don't (Score:2)
Should I know about this PHP? (Score:3, Interesting)
Is this PHP thing something I should know about? I Googled for it and it seems more proprietary than Perl or Python (didn't find a free download and docs). I have read the criticism comments that PHP i
Re:Should I know about this PHP? (Score:2)
Downloads are at http://www.php.net/downloads.php, docs at http://www.php.net/manual/en/.
I have read the criticism comments that PHP is in the Visual Basic category of encouraging weak minds to tackle strong tasks.
Today I read a comment somewhere (sadly I can't find it anymore) that compared PHP with MySQL: very forgiving for errors. If often fails silently, and potentially does something complete
Re:Should I know about this PHP? (Score:2)
The only real competitor to it is ASP, and really I'd rather use C++ for web scripting than that. Perl is way too slow and it's not designed for quickly scripting web sites. Python is promising but mod_python has not relly reached the maturity that it needs to be before I start learning it (I will however learn it eventually) and also it's not designed with web scripting in mind.
You say
Re:Should I know about this PHP? (Score:2)
What I mean is, for example, this section in the manual:
Not crashed yet (Score:3, Informative)
Re:Not crashed yet (Score:2)
I would say that it is somewhat cool. Interestingly enough, i bet it is more his bandwidth that is slowing it down rather then his server..over 1000 hit in a couple minutes is quite a feat for a hacked together proof of concept toy.
Re:Not crashed yet (Score:2)
-
Re:So much time... (Score:3, Insightful)
Re:So much time... (Score:2, Insightful)
Seriously, dude. This is Slashdot. While I agree that these (well, most of them) are worthwhile efforts, the simple fact is that most people on Slashdot are just looking for a little entertainment and escape from their day. We're geeks. We do geeky things.
Get over it.
Re:So much time...Missing Tags (Score:2)
Seriously yourself, Dude. Do I have to put [SARCASM]...[/SARCASM] markup tags on everything?
Re:Hardly new.. (Score:4, Funny)
MOD PARENT DOWN (Score:2)
Bzzt! Wrong! (Score:3, Insightful)
Re:Hardly new.. (Score:5, Informative)
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/ [ter.dk] ), 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.
Different window? (Score:5, Funny)
This is slashdot. I think you meant "different tab"
KB
Re:A live demonstration server is up... (Score:2, Informative)
Re:I For One... (Score:2, Funny)