PHP confession


  • Winner of the 2016 Presidential Election

    Continuing the discussion from Because maybe support is gonna be who saves me, cause after all I've got cryptowall:

    @Fox said:

    Those are some pretty great one-sentence horror stories. You should do one about PHP next.

    Non-lazy version of a PHP horror story:

    I once wrote a script that was supposed to look like a console window and show the console output of a command, live as it was being executed, inside an iframe. So I wrote a PHP script which did just that.

    Then we realized we had problems with HTTP timeouts, various PHP timeouts and some Apache timeout. So I wrote a wrapper script that was called instead of the program which disabled all timeouts and periodically output either the new program output or, if there was none, a few spaces to the console.

    Then, a few weeks later, we realized we needed to start the PHP script with some environment variables set, so I wrote a bash wrapper script. Then I changed the original script so that it would automatically figure out whether all necessary environment variables were set, and if not, call the bash script, which would then in turn set up the environment and call the PHP script again.

    Oh, did I mention that the command we originally wanted to call (and whose output we wanted to show in the iframe) was a PHP script as well?

    So, just to recap: PHP script -> calls PHP script via command line -> calls PHP script via command line -> calls bash script via command line -> calls PHP script via command line. Debugging that was a nightmare, especially when one of the scripts would fail due to some stupid configuration in some crappy shared hosting provider's chroot environment.
    It took me way too long to realize what a :wtf: I had built. It took us even longer to get rid of that thing and replace it with something sane.

    (This was a long time ago, so I don't remember all the details. I think it was 6 scripts total, but I don't remember what the 5th PHP script was for. Probably for getting the correct values for some of the environment variables from the database.)



  • @asdf said:

    I once wrote a script that was supposed to look like a console window

    Why, out of curiosity?


  • Winner of the 2016 Presidential Election

    @rc4 said:

    Why, out of curiosity?

    We were using a crappy CMS which had a search function, but would only index the pages if a user actually visited them. That, of course, would cause the page load to take forever. So I wrote a simple crawler that had to be executed whenever some content was changed.

    Since crawling a site would take quite some time, we wanted to give the site admin some feedback during that operation. This is how we came up with this thing (IIRC, we also used it in our Intranet for a simple server management GUI).



  • @asdf said:

    Then I changed the original script so that it would automatically figure out whether all necessary environment variables were set, and if not, call the bash script, which would then in turn set up the environment and call the PHP script again.

    Have you ever had an infinite recursing windows batch script before? It happened to me once when I was trying to request elevation for a batch script. Never again. I managed to kill it but it took some luck.


  • Winner of the 2016 Presidential Election

    I don't see what's so bad about thaE_STACK_OVERFLOW
    Connection Terminated.


  • Winner of the 2016 Presidential Election

    @LB_ said:

    Have you ever had an infinite recursing windows batch script before?

    Nope, only an infinite recursion with bash and PHP scripts, see above (occurred on one specific configuration, was a pain to debug).


  • sockdevs

    Hat off to you for :doing_it_wrong: PHP-style.

    Wondering if there should be a badge for inflicting PHP WTFery.



  • Well, that's halfway to the UNIX principle: do one thing and do it well.



  • @asdf said:

    Since crawling a site would take quite some time, we wanted to give the site admin some feedback during that operation. This is how we came up with this thing

    Of course, having a separate crawling process writing progress into a file, and a web frontend reading from that status file wasn't even considered a good idea to come up with...



  • @brotherelf said:

    Well, that's halfway to the UNIX principle: do one thing and do it well.

    Do half of thing and do it half-well?


  • Winner of the 2016 Presidential Election

    @wft said:

    Of course, having a separate crawling process writing progress into a file, and a web frontend reading from that status file wasn't even considered

    IIRC, that's what they're doing now.



  • @sloosecannon said:

    STACK_OVERFLOW

    Yep, the code I tried was indeed based on code from that place.



  • @rc4 said:

    @asdf said:
    I once wrote a script that was supposed to look like a console window

    Why, out of curiosity?

    Well, I've also done that before...

    I think the most fun thing was when I tried to do net stop Apache; net start Apache... then I learned that I should have put that in a batch file.



  • @rc4 said:

    Why, out of curiosity?
    Continuous integration web interfaces do this (in a much better way) - for example, Travis CI's builds let you watch the build log in real time, and it even works as an actual console so download progress bars and such can overwrite parts of the screen correctly. Obviously this isn't done by hanging a PHP script's output...


  • Discourse touched me in a no-no place

    @asdf said:

    So, just to recap: PHP script -> calls PHP script via command line -> calls PHP script via command line -> calls bash script via command line -> calls PHP script via command line.

    Yo dawg, I heard you like PHP scripts...

    (inb4 appropriating culture)



  • are you sure you want to deal with the unnamed horrors that would arise from that?


  • sockdevs

    Dude, PHP as a day job. How much worse could it possibly get?



  • @Arantor said:

    if there should be a badge for inflicting PHP WTFery.

    Suspension? :trolleybus:



  • @Arantor said:

    Dude, PHP as a day job. How much worse could it possibly get?

    PHP at the weekends?


  • sockdevs

    I did write PHP for a personal project this weekend as GitHub will confirm.


Log in to reply
 

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