Stories
Slash Boxes
Comments

SoylentNews is people

posted by cmn32480 on Wednesday November 25 2015, @10:31AM   Printer-friendly
from the get-this-all-sewn-up dept.

As far as I can remember, PHP has always had a terrible reputation at handling very heavy (or asynchronous) tasks. For a long while if you wanted to parallelize long tasks you had to resort to forking through pcntl_fork which had its own issues, and you couldn't really handle the results of those tasks properly, etc.

As such, a habit has kind of developed where we go straight for more intricate solutions such as queuing (which just delays your task if anything), React PHP, or even using another language altogether. But PHP can do threading, and more importantly it's a lot easier than you probably think.

In this article I'm going to dive into the pthreads extension (short for POSIX Threads). It has been around for a while (since 2012) but I feel like too many people forget it exists or assume it is going to be painful to use – mostly because the official documentation is rather slim about it.


Original Submission

 
This discussion has been archived. No new comments can be posted.
Display Options Threshold/Breakthrough Mark All as Read Mark All as Unread
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
  • (Score: 5, Insightful) by Thexalon on Wednesday November 25 2015, @12:08PM

    by Thexalon (636) on Wednesday November 25 2015, @12:08PM (#267956)

    As far as I can remember, PHP has always had a terrible reputation at handling anything important or complex.

    It spent 15+ years without any coherent design and a lot of legacy code was written that reflects that lack of design. And to add insult to injury, that legacy code is exactly why it persists. In particular, a lot of web developers are of the viewpoint that Wordpress must be used at all times regardless of what the customer actually needs (mostly because they've never even considered using anything else).

    --
    The only thing that stops a bad guy with a compiler is a good guy with a compiler.
    Starting Score:    1  point
    Moderation   +3  
       Insightful=2, Informative=1, Total=3
    Extra 'Insightful' Modifier   0  
    Karma-Bonus Modifier   +1  

    Total Score:   5  
  • (Score: 1, Disagree) by xav on Wednesday November 25 2015, @12:19PM

    by xav (5579) on Wednesday November 25 2015, @12:19PM (#267960)

    s/PHP has/PHP programmers have/

    FTFY

    • (Score: 2) by TheRaven on Wednesday November 25 2015, @04:51PM

      by TheRaven (270) on Wednesday November 25 2015, @04:51PM (#268050) Journal
      Good programmers can write good code in any language. Bad programmers can write bad code in any language. But good programmers look at PHP, see how insanely hard writing good code would be, and pick a less-bad language. The fact that JavaScript is a less-bad language for server-side programming is a big hint that PHP really should die.
      --
      sudo mod me up
      • (Score: 0) by Anonymous Coward on Wednesday November 25 2015, @08:37PM

        by Anonymous Coward on Wednesday November 25 2015, @08:37PM (#268130)

        php is no worse than any other language, and its one of the easiest for programming web apps, so to all the naysayers out there... get over it already

        it probably suffers from tall poppy syndrome more than anything because some of the largest and busiest websites use it (such as facebook and wikipedia), and people who prefer other languages get all pissy about it

        • (Score: 2, Disagree) by TheRaven on Friday November 27 2015, @11:14AM

          by TheRaven (270) on Friday November 27 2015, @11:14AM (#268615) Journal

          php is no worse than any other language

          That's simply not true. I can't be bothered to explain the myriad things that make PHP worse than any other mainstream language, but fortunately someone else has already done an excellent job [eev.ee]. Most languages have their quirks (JavaScript's weird semicolon insertion and lack of sensible number types, for example), but PHP is unique in being composed entirely from poorly composed quirks.

          --
          sudo mod me up
    • (Score: 2) by Thexalon on Thursday November 26 2015, @03:49AM

      by Thexalon (636) on Thursday November 26 2015, @03:49AM (#268233)

      No, I'm referring to PHP the language. My favorite example of how terrible it is: What happens when an error condition is encountered? The answer is *any* of the following, depending on the exact nature of the error condition:
      - The PHP process seg-faults and dies.
      - An exception is thrown up the call stack that may be caught and handled.
      - The error_handler function, if any is registered, is called. If not, an error message is sent to the output, and execution sometimes is halted.
      - The shutdown_handler function, if any is registered, is called. If not, an error message is sent to the output and execution halted.
      - The function spits a warning out to the user, and then the script attempts to continue, potentially with bad data.
      - The function quietly returns an invalid value that looks extremely similar or even identical to a legitimate value.
      - The function quietly returns a value that isn't remotely like a legitimate value, but provides no information whatsoever about what might have gone wrong. You have to call another function to find out what the error was.

      Compare that to well-designed languages, where what happens when things go wrong is something along the lines of:
      - An exception is thrown up the call stack that may be caught and handled.

      Once you experience those options, the PHP situation seems really truly insane.

      --
      The only thing that stops a bad guy with a compiler is a good guy with a compiler.
  • (Score: 1, Disagree) by Anonymous Coward on Wednesday November 25 2015, @04:18PM

    by Anonymous Coward on Wednesday November 25 2015, @04:18PM (#268040)

    In true PHP style, if something new is available in version 5.3.1, it will have its API changed in 5.3.2 (so calling it like you did in 5.3.1 fails), and it won't be available in 5.4.

    After riding that train a couple of times, I said "fuck PHP".

    • (Score: 0) by Anonymous Coward on Thursday November 26 2015, @08:21AM

      by Anonymous Coward on Thursday November 26 2015, @08:21AM (#268262)

      why didn't you say "fuck $whatever_api_you_were_using"?

      classic case of throwing the baby out with the bathwater