Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Three Devs & A Maybe:
Episode 78 - PHP Internals catch-up with Joe Watkins
Nov 24, 2015 @ 09:58:04

The Three Devs and a Maybe podcast has a new episode posted today with special guest Joe Watkins, PHP internals developer and developer on the APCu extension. They catch up with Joe and what's been happening in the world of PHP internals lately (and the flurry of excitement around PHP 7).

On this weeks show we are lucky to be joined by recurring guest and friend of the show Joe Watkins. We start of discussion with the upcoming PHP 7 release, reasoning behind why it has been postponed, the bright future of adoption to the release compared to previous versions and how the release gets packaged up for different distributions.

Other topics mentioned in this latest episode include:

  • "uopz" (User Operations for Zend)
  • the pthreads polyfill
  • the recent APCu events and additions

The show notes also link to several of Joe's projects on GitHub for reference. You can listen to this latest episode either through the in-page audio player or by downloading the mp3. Also be sure to subscribe to their feed if you enjoy the episode and want to hear more.

tagged: threedevsandamaybe podcast ep78 joewatkins interview phpinternals php7 apcu pthreads useroperations uopz

Link: http://threedevsandamaybe.com/php-internals-catch-up-with-joe-watkins/

Madewithlove Blog:
Thread carefully
Nov 16, 2015 @ 11:55:58

In a post to the Madewithlove blog Maxime Fabre takes a look at threading in PHP using the pthreads support that can be included into your PHP installation.

As far as I can remember, PHP has always had a terrible reputation at handling very heavy (or asynchronous) tasks. [...] 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.

They start by getting the pthreads support installed locally (it assumes you use OS X and the "brew" package manager but it can be installed manually too). The article starts off by defining some basic nomenclature from the pthreads world and gives a diagram of how it all fits together. From there it gets into some examples, showing a simple thread class to fetch Google results and how to fire off multiple instances at the same time. They then extend this even further and look at the concept of "workers" and using them to manage individual jobs. It then moves up the next level and looks at "pools" of workers and processing multiple workers at the same time.

There's also a section dealing with one "gotcha" that can happen with class inheritance between parent and child threads. They show how to work around this with a custom Worker class that performs the autoloading for you and is executed at the start of a Pool. Finally they cover the messaging between the child threads and, as a bonus, how threading could be used in a command bus setup.

tagged: threading tutorial pthreads example worker thread pool process commandbus messaging

Link: http://blog.madewithlove.be/post/thread-carefully/

Joe Watkins:
What Polly Really Wants
Sep 16, 2015 @ 11:49:03

Joe Watkins has a post to his site talking about polyfills and pthreads and some feedback he received during his work on the extension that allows for multi-threaded handling in PHP.

Recently a fellow githubber opened an issue for pthreads, they are writing a static analysis suite for PHP, and are attempting to integrate pthreads into their code. First thing to say is, I don't know where that will lead him. But it does give him the problem that a lot of environments don't have pthreads available, and or they aren't using a thread safe interpreter.

In the issue, he made the suggestion that we have a compatibility layer, a polyfill. I confess, this had never occurred to me before. Not only does it solve his problem but it actually serves as a useful tool ... I shall explain.

He starts by answering a question he's gotten a lot during his work on pthreads: "what's a good use case for threading?" Instead he answers a question that follows the intent a bit more: "What kind of code lends itself to threading?" He talks about units of work and separation of responsibility and how it "avoids synchronization" that could be caused by unforeseen circumstances. He instead recommends that, for most applications, true multi-threading probably isn't needed and a polyfill that simulates the functionality is probably good enough.

tagged: polyfill pthreads thread multithread synchronization

Link: http://blog.krakjoe.ninja/2015/09/what-polly-really-wants.html

Three Devs & A Maybe Podcast:
PHP Internals, pthreads and PHPDBG with Joe Watkins
May 29, 2014 @ 10:48:54

In the latest episode of the Three Devs and a Maybe podcast, Episode #26, Michael Budd, Fraser Hart, Lewis Cains and Edd Mann share some opinions about the PHP internals mailing list, pthreads and the PHPDBG project (with guest and project developer >Joe Watkins).

This week we are very lucky to have Joe Watkins from pthreads and PHPDBG fame on the podcast. Starting off discussion with the 'PHP Next Generation' drama, we move on to wrap-up our thoughts on the 'Is TDD dead' set of Google Hangouts. The topic then shifts onto our guest and how he got into programming and PHP - with the creation of pthreads and PHPDBG projects discussed. Finally, we finish off the podcast with the regular quiz.

Other topics mentioned in this latest episode include the work being done on PHPNG, routing with regular expressions and the neural networks video lecture. You can listen to this latest episode either through the in-page player or by downloading the episode directly.

tagged: threedevsandamaybe podcast ep26 internals pthreads phpdbg

Link: http://threedevsandamaybe.com/posts/php-internals-pthreads-and-phpdbg-with-joe-watkins/

Multithreading in PHP with pthreads
Aug 05, 2013 @ 11:21:31

On Reddit.com there's a post from krakjoe talking about using multithreating in PHP, specifically with pthreads. Unfortunately, there's several misconceptions about the pthreads (and concurrency) that still makes it difficult in PHP. The post lists a few of them:

  • PHP is not thread safe, there are lots of extensions that will give your application cooties.
  • pthreads is old fashioned
  • pthreads does not include everything you need to execute safely
  • pthreads unsafely shares memory among contexts in order to provide concurrent functionality
  • pthreads is beta and should be avoided at all costs

The author points out that pthreads are still in more of a "beta" state and probably shouldn't be used in production (though some do):

Multi-threading in PHP sounds like some sort of voodoo, for so long it's been something that was either impossible in the minds of php programmers, or a bad idea to try and emulate. pthreads doesn't emulate anything, it leverages bundled functionality and the object API to provide true userland multi-threading.
tagged: multithread pthreads extension summary misconceptions

Link: http://www.reddit.com/r/PHP/comments/1jo517/multithreading_in_php_with_pthreads/