August 5th, 2013
(written by lawrence krubner, however indented passages are often quotes). You can contact lawrence at: email@example.com
Synchronization: All of the objects that pthreads creates have built in synchronization in the ( familiar to java programmers ) form of ::wait and ::notify. Calling ::wait on an object will cause the context to wait for another context to call ::notify on the same object. This allows for powerful synchronization between Threaded Objects in PHP.
Wait, Threaded Objects ? A Stackable, Thread or Worker can be thought of, and should be used as a Threaded stdClass: A Thread, Worker and Stackable all behave in the same way in any context with a reference. Any objects that are intended for use in the multi-threaded parts of your application should extend the Stackable, Thread or Worker declaration. Which means they must implement run but may not ever be executed; it will often be the case that Objects being used in a multi-threaded environment are intended for execution. Doing so means any context ( that’s Thread/Worker/Stackable/Process ) with a reference can read, write and execute the members of the Threaded Object before, during, and after execution.
What’s missing is any sense of what once made PHP good: its simplicity. Nor is there any articulation of a theory of why PHP should try to imitate so much Java functionality. For gods sake, if you need multi-threading, why not switch to another language? Why not use a language where these ideas are natural to the concepts around which the language is based? (For instance, Clojure.)
Joe Watkins responded on Twitter:
He seems to have no idea what I’m saying. I’ll try again:
There are platforms that have mature support for threads. The JVM is one such platform. You can use many languages on the JVM: Groovy, Clojure, Scala, jRuby, and so many more. There is even a version of PHP that runs on the JVM. So if you need threads, why not use one of those languages? Why do threads need to be in PHP?Source