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.
(Score: 3, Interesting) by FatPhil on Wednesday November 25 2015, @12:11PM
However, he had the h/w working, and I don't, no matter how shitty his code is; so he wins, and I suck. (This is why I often will re-do tutorials that I've learnt from, so that others can see what I consider to be cleaner solutions, and not have to fight against head-scratching issues.)
Great minds discuss ideas; average minds discuss events; small minds discuss people; the smallest discuss themselves
(Score: 2) by wonkey_monkey on Wednesday November 25 2015, @01:21PM
One advantage springs to mind; if he ever decides he wants to provide something more complicated than a plain text file can provide - maybe a different text file at different times of day, or a list of commands generated on-the-fly depending on other server activity - he doesn't have to rewrite the slave.
systemd is Roko's Basilisk
(Score: 2) by FatPhil on Wednesday November 25 2015, @04:21PM
Great minds discuss ideas; average minds discuss events; small minds discuss people; the smallest discuss themselves
(Score: 2) by SanityCheck on Wednesday November 25 2015, @02:52PM
Hahaha perfect! I seen shit like that too. You would not even believe the piles of turds I stepped int hat were in PHP. I guess I feel vindicated that I reach for python when doing any sort of threaded work. But a lot of code here is in PHP, and IF I have to do use parrelism, I would like to continue with PHP.
(Score: 3, Insightful) by Fnord666 on Wednesday November 25 2015, @04:42PM
One of my biggest "dafuq?!?!?!" PHP moments came only 2 days ago. I was watching a youtube tutorial on how to do some h/w hacky thing, and the slave got commands from the master by polling a file residing a webserver, whilst the controller was a webpage invoking a PHP script which wrote to that command file. Nothing wrong with that, you say, except that the master was wget/curling "http://myserver/test.php" and test.php contained nothing but whatever is PHP for "return the contents of test.txt". The concept that the slave could just wget "http://myserver/test.txt" had never occured to this programmer who wanted to solve even non-problems with the PHP hammer. And the rest of the code was shitty too.
Because coding the client software to retrieve and parse a text file results in tightly coupled components. The solution given in the tutorial is significantly more loosely coupled [wikipedia.org] and changes in the server side representation of the data doesn't require matching changes in the client side code. This is a good thing.
(Score: 2) by FatPhil on Thursday November 26 2015, @12:05PM
If anything changes, you still need to change 2 endpoints.
Great minds discuss ideas; average minds discuss events; small minds discuss people; the smallest discuss themselves