You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
855 B

4 years ago
  1. <?PHP
  2. /**
  3. * struct
  4. * {
  5. * unisgned char type;
  6. * uint32_t time;
  7. * uint32_t serid;
  8. * uint32_t length;
  9. * char body[0];
  10. * }
  11. */
  12. function remoteCall(string $host, $port, string $data) {
  13. $length = strlen($data);
  14. $pack = pack('CNNNa*', 1, time(), 0, $length, $data);
  15. $client = new Swoole\Client(SWOOLE_SOCK_TCP);
  16. $client->set(array(
  17. 'open_length_check' => true,
  18. 'package_max_length' => 81920,
  19. 'package_length_type' => 'N',
  20. 'package_length_offset' => 9,
  21. 'package_body_offset' => 13
  22. ));
  23. if (!$client->connect($host, $port, 0.5)) {
  24. return false;
  25. }
  26. $client->send($pack);
  27. $pack = $client->recv();
  28. $ret = unpack('Ctype/Ntime/Nserid/Nlength/a*data', $pack);
  29. return $ret['data'];
  30. }
  31. $ret = remoteCall("127.0.0.1", "5188", "sasa");
  32. echo $ret;
  33. ?>