set.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. $table = new swoole_table(1024);
  3. $table->column('id', swoole_table::TYPE_INT, 4); //1,2,4,8
  4. $table->column('name', swoole_table::TYPE_STRING, 64);
  5. $table->column('num', swoole_table::TYPE_FLOAT);
  6. $table->create();
  7. //$worker = new swoole_process('child1', false, false);
  8. //$worker->start();
  9. //
  10. //child
  11. function child1($worker)
  12. {
  13. global $table;
  14. $s = microtime(true);
  15. $table->set('tianfenghan@qq.com', array('id' => 145, 'name' => 'rango', 'num' => 3.1415));
  16. $table->set('350749960@qq.com', array('id' => 358, 'name' => "Rango1234", 'num' => 3.1415));
  17. $table->set('hello@qq.com', array('id' => 189, 'name' => 'rango3', 'num' => 3.1415));
  18. $table->set('tianfenghan@qq.com', array('id' => 145, 'name' => 'rango', 'num' => 3.1415));
  19. $table->set('350749960@qq.com', array('id' => 358, 'name' => "Rango1234", 'num' => 3.1415));
  20. echo "set - 5 use: ".((microtime(true) - $s) * 1000)."ms\n";
  21. }
  22. //master
  23. sleep(1);
  24. child1(1245);
  25. $s = microtime(true);
  26. for($i =0; $i < 1000; $i++)
  27. {
  28. $arr = $table->get('350749960@qq.com');
  29. }
  30. echo "get -5 use: ".((microtime(true) - $s) * 1000)."ms\n";
  31. $s = microtime(true);
  32. //$table->incr('tianfenghan@qq.com', 'id', 5);
  33. //$table->decr('hello@qq.com', 'num', 1.1);
  34. $ret1 = $table->get('350749960@qq.com');
  35. $ret2 = $table->get('tianfenghan@qq.com');
  36. $ret3 = $table->get('350749960@qq.com');
  37. $ret4 = $table->get('tianfenghan@qq.com');
  38. $ret5 = $table->get('hello@qq.com');
  39. echo "get -5 use: ".((microtime(true) - $s) * 1000)."ms\n";
  40. var_dump($ret1, $ret2, $ret3, $ret4, $ret5);
  41. echo "id:".$ret1['id']."\n";
  42. echo "name:".$ret1['name']."\n";
  43. echo "num:".$ret1['num']."\n";