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. exit;
  16. }
  17. public function test1(){
  18. // 文本加一个回车
  19. $buffer1 = 'abcdefghijklmn';
  20. // 在php中双引号中的\n代表一个换行符,例如"\n"
  21. $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"}'."";
  22. $buffer2 = 'abcdefghijklmn'."\n";
  23. // 与服务端建立socket连接
  24. $client = stream_socket_client('tcp://1.14.197.70:2349');
  25. // 以text协议发送buffer1数据
  26. //fwrite($client, $buffer1);
  27. // 以text协议发送buffer2数据
  28. fwrite($client, $buffer2);
  29. }
  30. public function index()
  31. {
  32. return $this->view->fetch();
  33. }
  34. }