simulation.php 559 B

1234567891011121314151617181920
  1. <?php
  2. /**
  3. * The script is used for simulating the usage of swoole_table() and guaranting its usability.
  4. */
  5. $table = new swoole_table(1024);
  6. $table->column('name', swoole_table::TYPE_STRING, 64);
  7. $table->column('id', swoole_table::TYPE_INT, 4); //1,2,4,8
  8. $table->column('num', swoole_table::TYPE_FLOAT);
  9. $table->create();
  10. while (true) {
  11. $i = rand(1, 1000);
  12. $if = rand(0,1);
  13. if ($if) {
  14. $table->set($i, ['id' => $i, 'name' => $i, 'num' => $i]);
  15. } else {
  16. $table->del($i);
  17. }
  18. var_dump('count ' . $table->count());
  19. }