1
Memcache似乎在pthread線程中不起作用。PHP:Pthread + Memcache的麻煩
我得到這樣的警告:
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();
}