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: 2) by engblom on Thursday November 26 2015, @06:32AM

    by engblom (556) on Thursday November 26 2015, @06:32AM (#268251)

    PHP lacked from the very beginning any kind of design. It was just a "perl simplifier", that slowly grew to become a popular tool for making dynamic sites. Even today you see a lot of strange things inside of PHP because it lacked a design from the very beginning. Things are inconsistent and some things are just not thought through at all.

    There are other programming language better suited if you need parallelism in your code. My own favorite is Clojure that is designed from the beginning to make multi-threading simple. Then there are alternatives like Erlang. Actually Wikipedia got a long list of programming languages doing concurrency and PHP is not mentioned there: https://en.wikipedia.org/wiki/List_of_concurrent_and_parallel_programming_languages [wikipedia.org]

    Starting Score:    1  point
    Karma-Bonus Modifier   +1  

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

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

    slowly grew to become a popular tool for making dynamic sites

    and there are very good reasons for that... perhaps you should investigate them

    or if php is so terribly designed, maybe someone should inform facebook and wikimedia foundation