Memcache は、pthread スレッド内では機能しないようです。
次の警告が表示されます。
Warning: Memcache::get(): No servers added to memcache connection in test.php on line 15
class Test extends Thread {
protected $memcache;
function __construct() {
$this->memcache = New Memcache;
$this->memcache->connect('localhost',11211 ) or die("Could not connect");
}
public function run() {
$this->memcache->set('test', '125', MEMCACHE_COMPRESSED, 50);
$val = $this->memcache->get('test');p
echo "Value $val.";
sleep(2);
}
}
$threads = [];
for ($t = 0; $t < 5; $t++) {
$threads[$t] = new Test();
$threads[$t]->start();
}
for ($t = 0; $t < 5; $t++) {
$threads[$t]->join();
}