base.php 934 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. class R
  3. {
  4. public function __construct()
  5. {
  6. $cid = \Swoole\Coroutine::getCid();
  7. echo "cid:$cid ".__CLASS__ . '#' . \spl_object_id((object)$this) . ' constructed' . PHP_EOL;
  8. }
  9. public function __destruct()
  10. {
  11. $cid = \Swoole\Coroutine::getCid();
  12. echo "cid:$cid ".__CLASS__ . '#' . \spl_object_id((object)$this) . ' destructed' . PHP_EOL;
  13. }
  14. }
  15. class Pool extends \Swoole\Coroutine\ObjectPool
  16. {
  17. public function __construct($type)
  18. {
  19. parent::__construct($type);
  20. }
  21. public function create()
  22. {
  23. return new R;
  24. }
  25. }
  26. $pool = new Pool("test");
  27. go(function() use ($pool){
  28. $object = $pool->get();
  29. $cid = \Swoole\Coroutine::getCid();
  30. echo "cid:$cid ".var_export($object,1)."\n";
  31. });
  32. go(function() use ($pool){
  33. $object = $pool->get();
  34. $cid = \Swoole\Coroutine::getCid();
  35. echo "cid:$cid ".var_export($object,1)."\n";
  36. });