mysql_poole_client_test.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2019/5/27
  6. * Time: 9:28
  7. */
  8. define('START_TIME', microtime(true));
  9. require __DIR__.'/../vendor/autoload.php';
  10. \app\lib\boot::init();
  11. $config = \app\lib\GlobConfigs::getKey('pgsqlpoole');
  12. $client = new swoole_client(SWOOLE_SOCK_TCP);
  13. $client->set(array(
  14. 'socket_buffer_size' => 1024*1024*8, //2M缓存区
  15. ));
  16. $rts= $client->connect('192.168.2.200', $config['poole_port'], 10) or die("连接失败");//链接mysql客户端
  17. if (!$rts){
  18. die("连接发生错误,操作中止\n");
  19. }
  20. $sql =("select * from members where id=57");
  21. $client->send($sql);
  22. $resdata = $client->recv();
  23. print_r(json_decode($resdata,true)) ;
  24. $sql ="update members set name='12-".rand(100,500)."' where id=57";
  25. $client->send($sql);
  26. $resdata = $client->recv();
  27. print_r(json_decode($resdata,true)) ;
  28. $sql ="select * from \"districts\" where id=1";
  29. $client->send($sql);
  30. $client->waitall();
  31. $resdata = $client->recv();
  32. print_r(json_decode($resdata,true)) ;
  33. /*
  34. $sql ="select * from \"districts\" where id>=1 and id<=300" ;
  35. $client->send($sql);
  36. $resdata = $client->recv();
  37. print_r(json_decode($resdata,true)) ;
  38. */
  39. $client->close();
  40. /*
  41. echo "收到: ".$resdata."\n" ;
  42. $resda=json_decode($resdata,true);
  43. $client->close();
  44. return json_encode($resda);
  45. */