• myname (unregistered)

    well, at least the memory doesn't run out...

  • Pyromancer (unregistered)

    Why blame the 'system'? They should blame PHP for all their bugs :)

  • Bob (unregistered)

    Why blame PHP? They should blame their developer for all their bugs.

  • manarth (unregistered)

    Why blame the developer? It's the tester who creates bugs.

  • Cpt (unregistered)

    Why blame the developer, the requirements were never formulated properly!

  • J (unregistered)

    Ultimately, it's the keyboard that is responsible.

  • Martin (unregistered)
    posting the file to one page, programmatically urlencoding the file, and then posting to a different page

    WTF??

  • (cs)

    Why to blame developers, when you can blame physicist who created the technology for creating computers and therefor for creating programming languages, and therefor for creating bugs. Actually we can blame Newton every single time when our code doesn't work.

  • CodeMonkey (unregistered)

    "prevent writing knowledge to programmer memory from running out of memory."

    Captcha: muhahaha

  • (cs)

    PHP? the developers?

    It's the use of computers that is the real WTF.

    Paper - it's the way forward!

  • Sam (unregistered)

    The real PHP here is the Pointy-Haired Programmer.

  • Cloak (unregistered)

    The real WTF is that they replaced a two-liner with 8 lines of code. And unless there is a real reason for that they replaced what looks like working code with a not-tested procedure.

  • (cs)

    Blame mother nature. She's the one who created the bugs and other insects. If it wasn't for these little crawlers, we would not have bugs. Just errors...

  • Googler (unregistered)

    libcurl? how about streams?

  • (cs)

    urlencoding. A file.

    riiiiiight...

    There are a few more programmers in this story that apparently have ran out of memory.

  • Michael.H (unregistered)

    the problem always lies between the keyboard and chair guys.

  • Rob (unregistered)

    The real WTF here is that I am not in tears from reading this. Why have two lines of code when you can have eight! 2 > 8 right guys? ... right...?

  • (cs)

    Brillant. 10/10

    Addendum (2007-10-08 09:58): http://support.microsoft.com/kb/208427

    Addendum (2007-10-08 10:01): I don't know why I bother on this url limit, the guy's concatenating the files before urlencoding them anyway.

    Addendum (2007-10-08 10:03): I don't know why I bother this concatenating stuff, the guy's unsetting the $contents anyway. Ouch!

  • Cloak (unregistered) in reply to Rob
    Rob:
    The real WTF here is that I am not in tears from reading this. Why have two lines of code when you can have eight! 2 > 8 right guys? ... right...?

    Yeaaaah! And it looks so enterprisy...

  • joeSchmoe (unregistered)

    It seems like the real WTF is that they are trying to URL encode the entire file instead of the URL to the file.

  • Cloak (unregistered) in reply to Williams
    Williams:
    Blame mother nature. She's the one who created the bugs and other insects. If it wasn't for these little crawlers, we would not have bugs. Just errors...

    We should actually blame GOD and send him to (programmer's) hell. After we will blame and prosecute the creators of GOD for having fucked up with the entire universe and it's surroundings.

  • (cs) in reply to manarth
    manarth:
    Why blame the developer? It's the tester who creates bugs.
    As a software tester, I resemble that remark!
  • Ben (unregistered)

    It went from 2 to 8 obviously because file_get_contents() (grab the entire file into a string) was introduced in PHP 4.3 and they wanted it to be compatible with older versions. (Only last week I had the same problem with a client's webhost using 4.1 or something)

    One WTF though that file() (grab the entire file into an array: one line per element) was not binary safe prior to version 4.3 so the whole thing is an exercise in futility! Needed to fopen(), then loop fread() until eof() then fclose(). Or just specify/use PHP 5.2 and be done with it. PHP4 will be dead very soon anyway.

    Plus someone was a little too unset()-happy. Stupid people/programmers are everywhere. You can't completely blame the tools.

  • Michael (unregistered) in reply to proko
    proko:
    Why to blame developers, when you can blame physicist who created the technology for creating computers and therefor for creating programming languages, and therefor for creating bugs. Actually we can blame Newton every single time when our code doesn't work.
    Physicists (like Newton) only discover what already exists. Ultimately this is all God's fault.
  • (cs) in reply to Ben
    Ben:
    Plus someone was a little too unset()-happy. Stupid people/programmers are everywhere. You can't completely blame the tools.

    In my experience you can always blame the tools -- either blame the tool the program uses, or the tool that wrote it!

  • (cs)

    exit; //optimized to save memory since files don't upload anyways.

    foreach (file($filename) as $line) { $contents.= $line; } $contents=urlencode($contents);

    unset($line); unset($contents); unset($_FILES);

  • AdT (unregistered)
    The Article:
    Due to the distributed nature of the site, uploading a file involved posting the file to one page, programmatically urlencoding the file, and then posting to a different page.

    Due to the what? No distributed nature of any sort can serve as an excuse for this insanity!

    WTF Author:
    prevent writing uploaded file to string from running out of memory

    Brillant! Here's a way to save even more memory:

    apachectl -k stop

  • Kinglink (unregistered) in reply to manarth
    manarth:
    Why blame the developer? It's the tester who creates bgs.

    HAHAHA! testers? you must be joking. Testers would require someone in the business to do something that's not their job, or us to hire someone else?

  • (cs)

    What a great reuse of variables. Quite Frugal !!

  • (cs) in reply to myname

    Er, um, isn't urlencode() the wrong thing to use, as it breaks ampersand escapes like   ... etc...?

    And isn't reading a line at a time kinda slow, memory-fragmenting, and sure to goof up on binary files?

  • Anonymously Yours (unregistered)

    Wait, where's the WTF? It seems like this prolongEmploymentContract() function is working just fine. The new guy must be fresh out of college or have scruples or something...

  • (cs) in reply to Michael
    Michael:
    proko:
    Why to blame developers, when you can blame physicist who created the technology for creating computers and therefor for creating programming languages, and therefor for creating bugs. Actually we can blame Newton every single time when our code doesn't work.
    Physicists (like Newton) only discover what already exists. Ultimately this is all God's fault.

    Oh, sure! Blame the old guy! I mean, it's not like he's never made a WTF (the platypus?! the avacado?!) but he's made some nice stuff, too. Like unicorns and faeries.

    What, no unicorns and faeries? Ok, screw that then.

  • Theo (unregistered) in reply to Michael
    Michael:
    Physicists (like Newton) only discover what already exists. Ultimately this is all God's fault.

    I assume you write "God" in the pantheist way, as a synonym for all the laws of nature, as Newton and Einstein did?

    (Oh my, did I just start a religion talk here? WTF?!?)

  • Anon (unregistered) in reply to Ancient_Hacker
    Ancient_Hacker:
    Er, um, isn't urlencode() the wrong thing to use, as it breaks ampersand escapes like   ... etc...?
    No - since they're sending it to libcurl, a web client library, they're apparently essentially calling a web service. URL encoding is the proper way to prepare data to be sent by either an HTTP GET or POST request[1]. Of course, it's the wrong way to send a file - the PUT method exists for a reason. (And there's multipart/form as mentioned below.)
    Ancient_Hacker:
    And isn't reading a line at a time kinda slow, memory-fragmenting, and sure to goof up on binary files?
    Mostly yes. It's guaranteed to be slower since it causes the read to be checked for newlines, and concatenating is pretty much guaranteed to cause more memory to be used than just allocating the entire file at once.

    And while it's likely true that it will goof up binary files, it doesn't have to. Assuming that it's not doing any character encoding conversion (is keeping the same binary values), and that the read line method keeps the newline, the final variable will contain the same data anyway. (Assuming, of course, that PHP supports null characters in its strings. Which it does to a degree. Not all PHP functions do, but...)

    [1] Technically, urlencode is only proper for a POST request sent as application/x-www-url-form-encoded (the default) versus multipart/form (the method usually used to send file contents). See RFC2388.

  • Synonymous Awkward (unregistered) in reply to Theo
    Theo:
    Michael:
    Physicists (like Newton) only discover what already exists. Ultimately this is all God's fault.

    I assume you write "God" in the pantheist way, as a synonym for all the laws of nature, as Newton and Einstein did?

    (Oh my, did I just start a religion talk here? WTF?!?)

    Oh, good, because you lot can be trusted to be civil and polite to each other even when you're not discussing contentious topics.

  • (cs) in reply to poochner
    poochner:
    Oh, sure! Blame the old guy! I mean, it's not like he's never made a WTF (the platypus?! the avacado?!)
    Back off. My homemade guacamole is the finest in the land, completely without equal.
  • Seb (unregistered)

    oh my god.. there are so many WTF in this code.

    1. Why making 8 out of 1 or 2 lines?
    2. WTF urlencode() a file? omg.. how about base64_encode
    3. Why posting a received file to another site? (ok, might have a reason, but this has to be a REALLY good one)
    4. WTF IS THIS GUY UNSETTING THE CONTENT HE'S TRYING TO POST!?

    OMG..

  • (cs) in reply to Theo
    Theo:

    I assume you write "God" in the pantheist way, as a synonym for all the laws of nature, as Newton and Einstein did?

    Einstein, yes, but Newton!? The man spent more time on theology than on physics. There's an entire Wikipedia article just on his personal religious views: http://en.wikipedia.org/wiki/Isaac_Newton%27s_religious_views

    Quote: "I have a fundamental belief in the Bible as the Word of God, written by those who were inspired. I study the Bible daily.".

  • (cs) in reply to FredSaw
    FredSaw:
    poochner:
    Oh, sure! Blame the old guy! I mean, it's not like he's never made a WTF (the platypus?! the avacado?!)
    Back off. My homemade guacamole is the finest in the land, completely without equal.
    I like guacamole, too. But the avacado is still a WTF.
  • W-Shadow (unregistered)

    Why would they need to urlencode() or base64 the file if they're using CURL to upload it? CURL can take care of that automatically.

  • Ben Evans (unregistered) in reply to FredSaw
    FredSaw:
    poochner:
    Oh, sure! Blame the old guy! I mean, it's not like he's never made a WTF (the platypus?! the avacado?!)
    Back off. My homemade guacamole is the finest in the land, completely without equal.

    Fred, if you are ever in Seattle, I challenge you to a Guac-Off (all in delicious good fun of course) :-P

  • - (unregistered)

    base64 adds a lot of extra bytes you don't need. If both servers were controlled by the company, there are many good alternatives.

    1. Write the file to disk, and then "ping" the remote webserver so that it knows there is a new file to download.

    2. If both servers are connected locally, just put the file in a shared folder

  • (cs) in reply to Ben Evans
    Ben Evans:
    Fred, if you are ever in Seattle, I challenge you to a Guac-Off (all in delicious good fun of course) :-P
    Guac-Off -- love it! Bad timing, as is often the case. A couple of years back my son lived in Bellingham and I used to fly into Sea-Tac to visit.

    Do you use fresh garlic in yours? I find it strange that here in Texas most guac-makers do not. It's one of the secrets of my recipe that make it stand out above the rest. :)

  • (cs) in reply to PSWorx
    PSWorx:
    urlencoding. A file.

    riiiiiight...

    There are a few more programmers in this story that apparently have ran out of memory.

    bang.

    q: why are they reposting files in url encoded format that were already uploaded? a: because they're all idiots

    who cares why the system is broken? the design was broken to begin with.

    i really don't see the WTF here...some dumbass developer thought it was clever to unset some variable that was actually needed...and? it's the dumbass designers who are really to blame for requiring this awkward work around in the first place.

  • (cs) in reply to Synonymous Awkward
    Synonymous Awkward:
    Oh, good, because you lot can be trusted to be civil and polite to each other even when you're not discussing contentious topics.
    Interesting, how even as you're categorizing the entire readership of WTF using sarcasm to attribute social crudity and viciousness, you exclude yourself.
  • ceegh (unregistered) in reply to Theo

    Yes, you did.

    Where'd you get that? Some lazy philosophy professor?

    Einstein was arguably deistic, but never stated anything along the lines of pantheism. (God can't "play dice" with the universe if He is the universe.)

    Newton was completely Christian in his religious thought, even if it did not always match the dogma of his day. All you have to do is read his writings on the subject, which there are a lot of.

  • ceegh (unregistered) in reply to Theo
    Theo:
    Michael:
    Physicists (like Newton) only discover what already exists. Ultimately this is all God's fault.

    I assume you write "God" in the pantheist way, as a synonym for all the laws of nature, as Newton and Einstein did?

    (Oh my, did I just start a religion talk here? WTF?!?)

    Dang, hate not hitting "quote". Just look above...

  • John (unregistered) in reply to proko
    proko:
    Why to blame developers, when you can blame physicist who created the technology for creating computers and therefor for creating programming languages, and therefor for creating bugs. Actually we can blame Newton every single time when our code doesn't work.

    Alan Turing did a lot of work with computation (and thus assembly) before the technology exists. How do you then blame the machines when computation can be down without?

  • (cs) in reply to ceegh
    ceegh:
    Einstein was arguably deistic, but never stated anything along the lines of pantheism. (God can't "play dice" with the universe if He is the universe.)

    I believe the "play dice" thing was meant to be figurative -- a comment on the philosophical inelegance of a universe ruled by chance, rather than an implicit assumption about a willful divinity.

    Here's a quote from his article "Science and Religion". It seems pretty clear to me that he doesn't believe in the "doctorine of a personal God, interfering with natural events".

    "The more a man is imbued with the ordered regularity of all events the firmer becomes his conviction that there is no room left by the side of this ordered regularity for causes of a different nature. For him neither the rule of human nor the rule of divine will exists as an independent cause of natural events. To be sure, the doctrine of a personal God interfering with natural events could never be refuted, in the real sense, by science, for this doctrine can always take refuge in those domains in which scientific knowledge has not yet been able to set foot."

  • (cs) in reply to poochner
    poochner:
    FredSaw:
    poochner:
    Oh, sure! Blame the old guy! I mean, it's not like he's never made a WTF (the platypus?! the avacado?!)
    Back off. My homemade guacamole is the finest in the land, completely without equal.
    I like guacamole, too. But the avacado is still a WTF.

    Okay, I'll bite: What the heck is WTF-y about avocados? Is there something I don't know about them? (Would I figure out the WTF if I just looked at the "avocado" entry on Wikipedia?)

Leave a comment on “unset() It, and Forget It!”

Log In or post as a guest

Replying to comment #:

« Return to Article