Index.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 showredis(){
  11. $list = Db::name('user')->order('id desc')->column('id');
  12. foreach($list as $key => $id){
  13. dump($id.':'.redis_matching_get($id));
  14. }
  15. exit;
  16. }
  17. public function clearredis(){
  18. $list = Db::name('user')->order('id desc')->column('id');
  19. foreach($list as $key => $id){
  20. $a = redis_matching_set($id,0);
  21. }
  22. exit;
  23. }
  24. public function test1(){
  25. // 文本加一个回车
  26. $buffer1 = 'abcdefghijklmn';
  27. // 在php中双引号中的\n代表一个换行符,例如"\n"
  28. $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"}'."";
  29. $buffer2 = 'abcdefghijklmn'."\n";
  30. // 与服务端建立socket连接
  31. $client = stream_socket_client('tcp://1.14.197.70:2349');
  32. // 以text协议发送buffer1数据
  33. //fwrite($client, $buffer1);
  34. // 以text协议发送buffer2数据
  35. fwrite($client, $buffer2);
  36. }
  37. public function index()
  38. {
  39. return $this->view->fetch();
  40. }
  41. }