Joe Watkins
In my third year of being a core contributor to PHP
Wrote pthreads, before being involved in internals
Since, wrote many extensions, APCu, uopz, JITFu, strict
One of the two initial developers of phpdbg
Went on a date with Phil Sturgeon once
I live and breathe internals, every day
Synchronous
Asynchronous
Neither of these are parallel execution
Parallel code is executed in more than one thread
Parallel != Asynchronous
Object Orientated
Modern-ish
Safety Built In
Mature
100,000 installations from PECL
Compatible with most expectations
Any OS with a Posix Thread implementation
PHP 5.3+ built with Zend Thread Safety
Documentation on php.net
Patience
Even More Patience
Front controllers do not need threading
Template engines do not need threading
Web requests do not need threading
Exhaust all avenues before making things wantonly complicated
Multi-threading is hard.
Do not be scared
Isolation
Isolation
Isolation
Co-existence is the only option !
Thread extends Threaded
Worker extends Thread
Threaded
Pool
Safety !
<?php
class Client extends Threaded {
public function __construct($url) {
$this->url = $url;
}
public function run() {
$this->response = file_get_contents($this->url);
}
public $url;
public $response;
}
$pool = new Pool(4);
while (@$i++ < 10) {
$pool->submit(new Client(sprintf(
"http://google.com/?q=%s", md5($i))));
}
$pool->shutdown();
?>
http://php.net/pthreads
http://github.com/krakjoe/pthreads
Examples on github
Issues on github
Stackoverflow, Room 11
krakjoe@php.net