The PHP Master Architect



  • So I was bored at work this morning and trolling a few forums, and I came across a gathering of some of the worst php programmers on the web possibly. Check out this gem of a thread:  http://forums.devnetwork.net/viewtopic.php?t=72877. The OP is convinced that he has unlocked the secret of multi threaded php applications. He even has the balls/ignorance to post his code on sourceforge. Quite possibly some of the most WTFy php I've ever seen.

    The best responses are from the people with 2k+ posts, while the noobs posts are humorous on a shocking stupidity level. Is this kind of crap common? It seems like everywhere I look I see this sort of thing...If people are this dumb maybe they should give up trying to write code? Btw if you take a look at the sourceforge page this app has gone through 5 iterations of release, even after the author was told many times that what he claimed his app did was impossible...My head Hurts



  • I gave up even trying to talk with most PHP "programmers".  Most of them are young and too stupid to listen to people that know better.



  • Brillant!

    If your PHP script is so slow that you start to think it requires multi-threading, then maybe you're in the wrong line of work.



  • @djork said:

    Brillant!

    If your PHP script is so slow that you start to think it requires multi-threading, then maybe you're in the wrong line of work.

    Especially if you think multi threading makes your application faster! Brilliant!



  • The logic in his posts is worse than that of a 10 year old.

    And what brain dead judge would give him an award for innovation?



  • I just find it incredibly hard to understand how someone who "sort of" knows what multi-threading is(though it's obvious from his PHP "implementation" that he doesn't) wouldn't realize that PHP is totally incapable of programmatically spawning threads. I'll probably end up working with this guy at some point professionally, if I don't already.



  • @aythun said:

    The logic in his posts is worse than that of a 10 year old.

    And what brain dead judge would give him an award for innovation?

    The idiot that runs PHPClasses.org. That site contains the most useless pieces of PHP code you've ever seen. Not to mention that the website itself is so ugly, I can't bear open it in a browser for fear of soiling that browser's reputation. Well, maybe IE 6. 



  • OK, so all it's doing is an XMLHttpRequest. How is that considered multi-threading? Andhe code in Threader.php hurts my eyes. Seriously, that's some ugly code (and I thought my old code was ugly).

    I'm thinking, for proper multi-threading, you'd do something like execute another PHP process on the server, have that PHP process open a socket and then communicate with it via the socket. I've never seen this done before (nor have I ever done any proper multi-threaded applications, the only time I did it was with a library I wrote in VB6... Can't remember what I did exactly), so I'm just taking a guess. Of course, I have no clue what you'd use multi-threading for in a PHP app 😛



  • Perhaps something like this, at least it's a valid approach: http://www.alternateinterior.com/2007/05/multi-threading-strategies-in-php.html

    (stupid edit timeout on this board)



  • @Daniel15 said:

    I'm thinking, for proper multi-threading, you'd do something like execute another PHP process on the server...

    Bzzt, wrong! Once you've spawned another process, it's not multi-threading, it's multi-processing.  As was stated ad nauseum in that thread, multi-threading in PHP can't be done.  The language doesn't support it, and any hacks you can come up with to get around that will either be:

    a) just that (a hack) at best,
    b) not multi-threading at all, or at worst of all
    c) all of the above

     That guy's solution falls under category (c).

     



  • @Nozz said:

    @Daniel15 said:

    I'm thinking, for proper multi-threading, you'd do something like execute another PHP process on the server...

    Bzzt, wrong! Once you've spawned another process, it's not multi-threading, it's multi-processing.  As was stated ad nauseum in that thread, multi-threading in PHP can't be done.  The language doesn't support it, and any hacks you can come up with to get around that will either be:

    a) just that (a hack) at best,
    b) not multi-threading at all, or at worst of all
    c) all of the above

     That guy's solution falls under category (c).

     

    Oops, my bad... Indeed, you're right :). I just couldn't think of the correct term to describe it ("multi-processing").



  • It is people like this that gives PHP a bad reputation.
    If only they would have understood what they are doing on all the levels.

    Php needs more datatypes, one for every sql query enabled extension. Seriously, some people need to be forcebly forced to escape their shit.



  • A perfect example of a guy who can bullshit himself out of anything to convince people he's the real genius while he's totally clueless

    But, to be honest, when I was young I used to create these kinds of things too. Hell, I'm sure we all created these things in our 'experimental' years

     



  • @GuntherVB said:

    A perfect example of a guy who can bullshit himself out of anything to convince people he's the real genius while he's totally clueless

    But, to be honest, when I was young I used to create these kinds of things too. Hell, I'm sure we all created these things in our 'experimental' years
     

    That guy can't bullshit his way out of a wet paper bag (?).  Nobody bought his crap, except for the goon who gave him that "award".

    I agree that there's nothing wrong with being young and enthusiastic, and yes, I was too once.  The difference between me and that guy though, is that if and when I came up with WTFs that were quite obviously the "wrong" solution, I would not dismiss every single comment that told me it was wrong.  I have a feeling that if he is like that when he is "young" (and we're only assuming he's young, he could just be "not that sharp"), he'll be like that when he is old and in the workforce as well.  Usually, people who don't listen early never listen.  That's the real problem with this story, and that's the reason I'll happily write him off as a "will never be any good as a software engineer" just based on that one (big) WTF.



  • I downloaded the code & examples before reading that thread on devnetwork.net. Taking it as a pure experimentation, his technique to download multiple files at the same time is quite creative ( while using a completely wrong vocabulary and WTFesque in the context of any real world application, but that's another point ) ; if he's a student, he's probably smarter than most other students in his class. I remember how it feels the first time you understand loops, pointers, recursion, IPC, network programming and so on ... that's ok to be proud the first time you understand how does XMLHttpRequest work. But proud for yourself, like when you finish a marathon. You think you're the king of the world for a few minutes, and then hope, for your own sanity, that this impression won't last, and keep going on other personal challenges. That attitude is sane when you're still in control and surrounded by sane people saying "hey, that's great for you. Now let's get back to everyday life". Or sane co-workers : "ok, great, looks fun ... now what about user's needs ?". But on forums, you'll always find clueless people to praise you, and that's not a good thing.

    It goes downhill when I finally read the thread. I've seen that pattern before, he's saying he is ready for any criticism, while in fact he can't stand it. He answers every single line, saying that the others did not even try to understand, or that he's being rude, or not open-minded, or incompetent, or ...

    That seems to be a mental illness that spreads across forums, and not only programming forums. I remember that skatedrive guy ( it's french-speaking, sorry ; it's some kind of rollerskating accessory that allegedly helps keeping balance, braking, whatever. ). That guy said to be open to criticism but when told it was completely useless ( or at least inconvenient for what it meant to be used ), he decomposed every single line of the message and answered to every point, not admiting any flaw in his design, instead backfiring his opponents : "did you even try ? Do you know what you're talking about ? What do you mean by (...) ? I didn't say that, you don't understand and you're not even trying". Throughout his ~70 replies, he keeps standing on his point in the same manner. It's funny because everyone loves to make fun of arrogant people. But when you try to be really empathetic with that person, it's disappointing and really sad. If you wanted to heal that kind of person, debug his mind instead of making fun of him, what would you do ? Is he to be considered braindead ?



  • There is nothing wrong with PHP when it is used correctly. Just there are so few people that actually do.

    I suppose the same is true of every language though sigh



  • You had me up to

     

    then make a PHP class Implements and Interfaces the Js Class

    That's when I realized he's kidding.

     ...

     What do you mean, he's [i]serious[/i]!?!



  • I was adding this to my post but the editing period expired:

    I believed people when they said PHP sucks when it was the only
    language I knew. Then I learned Java and C++, and saw you can write
    WTFs in those just as well. Different WTFs, perhaps, but no less WTFs.
    So I realized that calling a language stupid is blaming one's tool for one's own inability to frame a programming problem.
    There is no language that does a programmer's job for them, which is to
    think. If your PHP code is ugly, then your Java code will be ugly too
    (unless you know one language better than the other).



  • The difference is the barrier to entry to Java is low and PHP far lower than that. This alone means you'll have more WTFey code than other languages. IIt's true to say that different languages have different WTF tolerances and limits; some things you can do in C++ will make you look for the nearest bridge to chuck the computer/yourself off it, but Haskell for example is far saner and robust, and a sensible solution in CL could easily be a WTF tried elsewhere.

    I wouldn't go as far as calling languages stupid, but like a sharper, balanced knife, some languages can easily do the work of many others and even more.  Other languages are potato peelers, or food processors - they'll give you quicker and better results than the knife in some situations, but may be more challenging in others. Consider what you're trying to do. PHP might be a crappy knife, but it's still a knife nonetheless.



  • @Arancaytar said:

    I believed people when they said PHP sucks when it was the only
    language I knew. Then I learned Java and C++, and saw you can write
    WTFs in those just as well. Different WTFs, perhaps, but no less WTFs.
    So I realized that calling a language stupid is blaming one's tool for one's own inability to frame a programming problem.

    That is not why PHP sucks. This is why PHP sucks.



  • @asuffield said:


    That is not why PHP sucks. This is why PHP sucks.

    What, the wrong list of actually implemented functions?  There are a lot more than that that have been implemented.   



  • @asuffield said:


    That is not why PHP sucks. This is why PHP sucks.

    What, the wrong list of actually implemented functions?  There are a lot more than that that have been implemented.   



  • @asuffield said:

    That is not why PHP sucks. This is why PHP sucks.

    <code>$ wget -qO- http://.../Strings.pm | grep 'WILL NOT BE IMPLEMENTED' | wc -l<br/>
    74</code>

    Edit: This forum software sucks.
     



  • @ChZEROHag said:

    <code>$ wget -qO- http://.../Strings.pm | grep 'WILL NOT BE IMPLEMENTED' | wc -l<br/>
    74</code>

    Edit: This forum software sucks.

    In fact:

    $ cat (copy+paste ftw) | wc -l 

    86



  • Three in a row. Woo!

    For all its strengths (eh?) and weaknesses, PHP just seems to attract morons. Below is a representative line from the behemoth I'm currently being forced to hack on. All whitespace and formatting preserved exactly.

    if(!$this->db->error()) return true; else return false;



  • @asuffield said:

    That is not why PHP sucks. This is why PHP sucks.

    PHP sucks because of some random dude's crappy Perl library that doesn't even run?

    In other news: Bacon sucks because horses can't look up.



  • @superjer said:

    @asuffield said:

    That is not why PHP sucks. This is why PHP sucks.

    PHP sucks because of some random dude's crappy Perl library that doesn't even run?

    In other news: Bacon sucks because horses can't look up.

    That was beautiful.

    (Wipes a tear from his eye)



  • @MasterPlanSoftware said:

    @superjer said:

    PHP sucks because of some random dude's crappy Perl library that doesn't even run?

    In other news: Bacon sucks because horses can't look up.

    That was beautiful.

    (Wipes a tear from his eye)

     Yeah, but Big Al also says dog's can't look up....
     



  • @kaamoss said:

    @MasterPlanSoftware said:
    @superjer said:

    PHP sucks because of some random dude's crappy Perl library that doesn't even run?

    In other news: Bacon sucks because horses can't look up.

    That was beautiful.

    (Wipes a tear from his eye)

     Yeah, but Big Al also says dog's can't look up....

     Why is there a rifle above the bar?

     



  • @asuffield said:

    That is not why PHP sucks. This is why PHP sucks.



    That's also a pretty good example of why the Perl community sucks.  He decided to take a fairly big name for what amounts to a joke module.  And all of his "trivially implemented with a regular expression" snarky comments can be applied to a lot of Perl built-in subroutines.



  • @Cap'n Steve said:

    And all of his "trivially implemented with a regular expression" snarky comments can be applied to a lot of Perl built-in subroutines.

    Which ones would those be? 



  • Doesn't most of Perl consist of regular expressions? Perhaps I've only used a very small part of it otherwise...

    That said, Perl is a lovely language to [url=http://perl.plover.com/obfuscated/bestever.pl]obfusace[/url] on purpose, whereas PHP is ugly if you do not take great care to write elegantly. So I suppose Perl is better as far as elegance goes.

     But I'll still use PHP for everything that will generate web page output.

     

    Edit: Seems I obfuscated "obfuscate".



  • @Arancaytar said:

    Doesn't most of Perl consist of regular expressions? Perhaps I've only used a very small part of it otherwise...

    You have only used a very small part of it.



  • Ag, sies. Most PHP script are so short lived in execution.The only time my scripts exceed the default 30s execution time is when I've done something stupid.

     
    Is multi-threading really needed? I, too, wouldn't know what to do with it. Now, if someone wanted to write a daemon or something else a bit more persistent in PHP, then multi-threading would be useful. Hmmmm....a daemon written in PHP. That would be interesting....



  • @spxza said:

    Ag, sies. Most PHP script are so short lived in execution.The only time my scripts exceed the default 30s execution time is when I've done something stupid.

     
    Is multi-threading really needed? I, too, wouldn't know what to do with it. Now, if someone wanted to write a daemon or something else a bit more persistent in PHP, then multi-threading would be useful. Hmmmm....a daemon written in PHP. That would be interesting....

    Write the PHP interpreter in PHP.



  • @m0ffx said:

    Ag, sies. Most PHP script are so short lived in execution.The only time my scripts exceed the default 30s execution time is when I've done something stupid.

    Is multi-threading really needed? I, too, wouldn't know what to do with it. Now, if someone wanted to write a daemon or something else a bit more persistent in PHP, then multi-threading would be useful. Hmmmm....a daemon written in PHP. That would be interesting....

    If your PHP script is for a webpage, it would be difficult to determine what the output should be if you've multithreaded your script.  I'm imagining <tables> and <divs> in wildly different places each time the script runs.  I doubt any sane person would multithread that kind of script, but I may just be insane enough to play around with it.

    @spxza said:

    Write the PHP interpreter in PHP.

    Oh Please God No! 



  • <?php

    eval(file_get_contents($argv[1]));

    ?> 



  • @asuffield said:

    @Cap'n Steve said:

    And all of his "trivially implemented with a regular expression" snarky comments can be applied to a lot of Perl built-in subroutines.

    Which ones would those be? 



    chomp(), chop(), lc(), uc(), etc.  Hell,  join() can be "trivially implented" with a loop so why have that built in?



  • @Cap'n Steve said:

    @asuffield said:

    @Cap'n Steve said:

    And all of his "trivially implemented with a regular expression" snarky comments can be applied to a lot of Perl built-in subroutines.

    Which ones would those be?



    chomp()

    The documentation explains why this is not equivalent to any regexp. 

    chop()

    Same here. Why haven't you read the documentation?

     

    lc(), uc()

    These are the (extremely complex) functions called by the regexp substitution operator. They don't have to be exposed, but they do have to be there, so there's no reason not to expose them. Note that this is locale-sensitive.


    Hell, join() can be "trivially implented" with a loop so why have that built in?

    Functional programming. It could have been put in List::Util instead, but that's hardly important.
     



  • @m0ffx said:

    Write the PHP interpreter in PHP.

    You could probably do something crazy with the Tokenizer functions...

    Hmmmm....a daemon written in PHP. That would be interesting....

    Already been done... Someone wrote a DNS server in PHP. I can't find the URL at the moment, but it was posted to phpclasses.



  • Just because it's locale sensitive doesn't mean you couldn't implement it yourself. I have no idea what you're talking about with chomp and chop. The [url=http://perldoc.perl.org/functions/chop.html]chop[/url] page even gives an example of an equivalent regular expression, it just says it's less efficient. And feel free to explain how s|$/$|| doesn't have the same effect as chomp.



  • @Cap'n Steve said:

    Just because it's locale sensitive doesn't mean you couldn't implement it yourself.

    Which is a stupid argument unless you use only assembler and implement everything by hand perfectly. (Libraries aren't perfect, but they get more testing than most code.) Besides, the world doesn't need more WTFs caused by people who are only aware of 26 letters of an alphabet...

    I believe your regex only works when $/ is a newline (or other line terminator string) and won't work as chomp does when $/ is undefined or a reference.

    chop is more efficient than a regex. That's all.

    So, implement substr as a regex for us 🙂 



  • @Cap'n Steve said:

    Just because it's locale sensitive doesn't mean you couldn't implement it yourself.

    I can tell from this comment that only one of us has ever implemented unicode case folding. 



  • @Otterdam said:

    @Cap'n Steve said:

    Just because it's locale sensitive doesn't mean you couldn't implement it yourself.

    Which is a stupid argument unless you use only assembler and implement everything by hand perfectly. (Libraries aren't perfect, but they get more testing than most code.) Besides, the world doesn't need more WTFs caused by people who are only aware of 26 letters of an alphabet...



    That's exactly my original point.  Just because I can implement something doesn't mean I wouldn't rather have a built-in function do it for me.



  • The real WTF is this

    11. Please use proper, complete
    spelling when posting in the forums. AOL Speak, leet speak and other
    abbreviated wording can confuse those that are trying to help you (or
    those that you are trying to help). Please keep in mind that there are
    many people from many countries that use our forums to read, post and
    learn. They do not always speak English as well as some of us, nor do
    they know these aberrant abbreviations. Therefore, use as few
    abbreviations as possible, especially when using such simple words.

     

    Is seems that after the "that unfortunate business" my year nine teacher got a new job as mister-bossy-pants-moderator on DevNetwork Forums.

     

     



  • Alot of forums have that rule, some are more strict than others. Personally I would rather have that rule enforced, it makes it easier for ESL people to learn correct english, and it actually gives a sense of maturity throughout the boards.



  • @MasterPlanSoftware said:

    @djork said:

    Brillant!

    If your PHP script is so slow that you start to think it requires multi-threading, then maybe you're in the wrong line of work.

    Especially if you think multi threading makes your application faster! Brilliant!

    Brilliant!

    I bet he's database bound anyways! 



  • Desktop languages already have multi-threading centuries ago (posted by OP somewhere in the middle of that thread)

     
    Another one of Benny Franklin's fine ideas I'm sure.
     



  • @spxza said:

    Hmmmm....a daemon written in PHP. That would be interesting....

    Funny you should mention that. An excerpt from the mess I am no longer having anything to do with (with its name obfuscate):

    #!/bin/sh
    BALLD=/ball/balld/balld.php
    OUTPUT_LOG=/var/log/ball/balld.out
    BALLD_PID=`ps ax |grep balld |grep php |grep -v grep | awk '{print $1}'`
    ...
                    echo -n "Starting Ball Daemon..."
                    $BALLD >$OUTPUT_LOG 2>&1 &
                    echo "balld."

    And, for kicks, here's some more:

    #!/usr/bin/php -q
    ...
    while(! $quit) {
    ...
            $client = socket_accept($socket);
            logmsg("Connection received", 1);
            $input = socket_read($client, 4096);
    
            logmsg("Received : " . $input, 2);
            if($quiet == 0)
                    echo "Received : " . $input . "\n";
    
            $command = explode($split_char, $input, 2);
            if(! $command[1]) $command[1] = "null";
    
            if( ${$command[0]})
                    eval('$output = ' . ${$command[0]} . "(" . $command[1] . ");");
            else
                    $output = $error_msg;
    
            logmsg("Sending : " . $output, 2);
            socket_write($client, $output);
    
            socket_close($client);
            logmsg("Connection closed", 2);
    }

    And if that's not enough:

    if($halt) {
            logmsg("Shutting down system...\n");
            exec("/sbin/halt");
    }

    Yes, it all runs as root...



  • @aikii said:

    I remember that skatedrive guy

    Hehe I was quite amused by what you (or some mysterious other person called aikii) said about removing the frame from a bicycle to get a skatedrive and a unicycle... until I noticed that there is a diagram of exactly that on the front page of skatedrive.com.

    Actually I don't really see why it's completely useless, I have awful balance so I could do with something like that to learn to skate (not all-terrain though). But I didn't bother reading past the first few pages, and I don't really know anything about that kind of thing. 


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.