connect('localhost', 11211) or die ("Could not connect to memcached"); for($i = 0; $i < NOPS/NTHREADS; $i++) { $hot = $cache->get('hot'); $hot = $hot + 1; $cache->set('hot', $hot); } $cache->close(); } function test4() { $cache = new Memcache(); $cache->connect('localhost', 11211) or die ("Could not connect to memcached"); for($i = 0; $i < NOPS/NTHREADS; $i++) { $cache->increment('hot'); } $cache->close(); } function dispatch($me, $f) { $cmd = sprintf('%s -d include_path=%s %s %s', PHP_BINARY, get_include_path(), $me, $f); shell_exec($cmd); } function test($lbl, $me, $f) { $cache = new Memcache(); $cache->connect('localhost', 11211) or die ("Could not connect to memcached"); $t1 = gettimeofday(TRUE); $cache->set('hot', 0); $t = array(); for($i = 0; $i < NTHREADS; $i++) { $t[] = new Thread(); $t[$i]->addFunctionTask('dispatch', $me, $f); } for($i = 0; $i < NTHREADS; $i++) { $t[$i]->start(); } for($i = 0; $i < NTHREADS; $i++) { $t[$i]->join(); } $hot = $cache->get('hot'); $t2 = gettimeofday(TRUE); echo sprintf("%s : %d = %d (%d ms)\r\n", $lbl, $hot, NOPS, (int)(($t2 - $t1) * 1000)); $cache->close(); } if(count($argv) < 2) { test('No handling', $argv[0], 'test1'); test('Atomic increment', $argv[0], 'test4'); } else { $argv[1](); } ?>