<?php
class Test extends Thread {
protected static $memcache;
public function run() {
self::$memcache = new Memcache;
if (!self::$memcache->connect('127.0.0.1',11211 ))
throw new Exception("Could not connect");
self::$memcache->set('test', '125', MEMCACHE_COMPRESSED, 50);
$val = self::$memcache->get('test');
echo "Value $val.\n";
}
}
$threads = [];
for ($t = 0; $t < 5; $t++) {
$threads[$t] = new Test();
$threads[$t]->start();
}
for ($t = 0; $t < 5; $t++) {
$threads[$t]->join();
}
class Test extends Thread {
protected static $memcache;
public function run() {
self::$memcache = new Memcache;
if (!self::$memcache->connect('127.0.0.1',11211 ))
throw new Exception("Could not connect");
self::$memcache->set('test', '125', MEMCACHE_COMPRESSED, 50);
$val = self::$memcache->get('test');
echo "Value $val.\n";
}
}
$threads = [];
for ($t = 0; $t < 5; $t++) {
$threads[$t] = new Test();
$threads[$t]->start();
}
for ($t = 0; $t < 5; $t++) {
$threads[$t]->join();
}
var_dump($threads);
感谢原作者:http://stackoverflow.com/questions/22978916/php-pthread-memcache-trouble