Index.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace app\index\controller;
  3. use app\common\controller\Frontend;
  4. use think\Db;
  5. class Index extends Frontend
  6. {
  7. protected $noNeedLogin = '*';
  8. protected $noNeedRight = '*';
  9. protected $layout = '';
  10. public function testredis(){
  11. $list = Db::name('user')->column('id');
  12. foreach($list as $key => $id){
  13. $a = redis_matching_set($id,0);
  14. }
  15. }
  16. public function test1(){
  17. // 文本加一个回车
  18. $buffer1 = 'abcdefghijklmn';
  19. // 在php中双引号中的\n代表一个换行符,例如"\n"
  20. $buffer2 = '{"type":"say", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello"}'."";
  21. $buffer2 = 'abcdefghijklmn'."\n";
  22. // 与服务端建立socket连接
  23. $client = stream_socket_client('tcp://1.14.197.70:2349');
  24. // 以text协议发送buffer1数据
  25. //fwrite($client, $buffer1);
  26. // 以text协议发送buffer2数据
  27. fwrite($client, $buffer2);
  28. }
  29. public function index()
  30. {
  31. return $this->view->fetch();
  32. }
  33. }