coro_serialize.php 838 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. use Swoole\Coroutine as co;
  3. class Obj {
  4. public $a;
  5. protected $b;
  6. private $c;
  7. var $d;
  8. function __construct($a, $b, $c, $d) {
  9. $this->a = $a;
  10. $this->b = $b;
  11. $this->c = $c;
  12. $this->d = $d;
  13. }
  14. function __sleep() {
  15. // co::sleep(0.5);
  16. $client = new Swoole\Coroutine\Client(SWOOLE_SOCK_TCP);
  17. $res = $client->connect('127.0.0.1', 9501, 10);
  18. var_dump($res);
  19. if ($res)
  20. {
  21. echo("connect success. Error: {$client->errCode}\n");
  22. }
  23. echo "sleep\n";
  24. return array('a', 'b', 'c');
  25. }
  26. // function __wakeup() {
  27. // $this->d = $this->a + $this->b + $this->c;
  28. // }
  29. }
  30. $o = new Obj(1, 2, 3, 4);
  31. co::create(function() use($o) {
  32. $serialized = serialize($o);
  33. $unserialized = unserialize($serialized);
  34. echo "res:".var_export($unserialized,1)."\n";
  35. echo "call user\n";
  36. });