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 SanityCheck on Wednesday November 25 2015, @03:00PM

    by SanityCheck (5190) on Wednesday November 25 2015, @03:00PM (#268011)

    Yes that is true, it is not ideal solution for a lot of reason, especially where quux has arguments dependent on foo and bar, not to mention that these arguments might now have to be checked to ensure they were not altered by the client. I think that just makes a Swiss cheese out of your whole system.

    It can work for systems where the user just needs to be authenticated, and you guess he has access to all the resources of a certain level based on their level of access (I do this with some legacy systems), and just add sanity checks for the arguments. If he changes the arguments it won't matter since he could call that function with any arguments and not have any problems during course of normal use of the system (assuming his account has the sufficient level of access).

    If you had to ensure for security reasons that this user can call this function with these particular arguments, then you would just end up having to double check so much crap, usually with database queries galore. You would end up doing foo and bar inside quux again just to ensure that it was a valid function call.

    Starting Score:    1  point
    Karma-Bonus Modifier   +1  

    Total Score:   2