Slashdot Mirror


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."

11 of 295 comments (clear)

  1. Re:Unlimited connections, really? by PugMajere · · Score: 2, Insightful

    Amazingly, it was still up when I posted this.

    Fairly slow, but still rather impressive.

  2. Re:That is a VERY limited system.... by Doppler00 · · Score: 4, Insightful

    Yeah, writing a web server is "inappropriate" languages is pretty easy. As long as you can send bytes out of a port, it's pretty easy.

    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.

  3. Re:That is a VERY limited system.... by igrp · · Score: 5, Insightful
    Hmm... To quote the server's main page:

    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.

    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"?

  4. Re:That is a VERY limited system.... by Fearless+Freep · · Score: 5, Insightful

    Yeah, I wrote a quick and dirty proof of concept distributed object client/server in Python in about two hours, but I wouldn't post it to slashdot. Quick and dirty proofs of concepts are what progreammers do every day...so what?

  5. ... unlimited ... by AchilleTalon · · Score: 2, Insightful
    "... to support an unlimited number of simultaneous TCP ..."
    Hey! Wake up, we are on /. and anyone here knows there is nothing unlimited in the universe, but human stupidity.

    --
    Achille Talon
    Hop!
  6. Re:That is a VERY limited system.... by nlh · · Score: 3, Insightful

    That is a typical obnoxious-geek response and should be modded as such.

    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 that to yourself.

  7. Re:That is a VERY limited system.... by Anonymous Coward · · Score: 2, Insightful

    could you do better?

    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.

  8. Re:So much time... by Enrico+Pulatzo · · Score: 2, Insightful

    that's an easy one. Cancer doesn't come with documentation. One can flesh out an implementation of a spec, but figuring out the great unknown is quite a bit more difficult.

  9. Re:So much time... by applef00 · · Score: 2, Insightful

    Maybe his skills don't lie in research medicine, preemptive military strategy, and/or patent law. Heck, maybe not even in criminal investigation!

    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.

  10. Bzzt! Wrong! by Anonymous Coward · · Score: 3, Insightful

    All of those results are web related applications, e.g. application servers. None are web servers except for Reptile, which is written in Python!

  11. On the topic of pointless accomplishments... by fzammett · · Score: 4, Insightful

    About three years ago I wrote a very simplistic database server in Prolog on an Atari 800XL. This was of course AFTER I wrote a very simplistic Prolog compiler :) The database server accepted VERY basic SQL queries and could query against data on a floppy OR a cassette drive (yes, it supported cassettes!) and would display the results on the screen, nothing more (well, you could print it too, but I didn't have a printer, so I'm not 100% sure that would have worked).

    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 :) Both were fun as hell to do though, made us think in very unconventional ways, and forced us at the end to say "well, that's cool, but what the hell is the point?!?"

    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.

    --
    If a pion (n-) collides with a proton in the woods & noone is there to hear it, does lamdba decay into the source pa