msgutil.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 2017/2/26
  6. * Time: 下午7:36
  7. */
  8. class MsgStates extends Stackable
  9. {
  10. public function run() {
  11. }
  12. }
  13. class StatesHelper
  14. {
  15. static public function onIndex($states,$msg)
  16. {
  17. $type = $msg['type'];
  18. if($type == 'tags') {
  19. $states['tags'] = true;
  20. }
  21. }
  22. static public function fetch_state($tag)
  23. {
  24. global $gMessageStates;
  25. global $gMessageLock;
  26. Mutex::lock($gMessageLock);
  27. if(is_array($gMessageStates) && array_key_exists($tag,$gMessageStates))
  28. {
  29. $state = $gMessageStates[$tag];
  30. if($state == true) {
  31. $gMessageLock[$tag] = false;
  32. }
  33. }
  34. else {
  35. $gMessageLock[$tag] = false;
  36. $state = true;
  37. }
  38. Mutex::unlock($gMessageLock);
  39. return $state;
  40. }
  41. static public function init()
  42. {
  43. global $gMessageStates;
  44. global $gMessageLock;
  45. Mutex::lock($gMessageLock);
  46. $gMessageStates['tags'] = true;
  47. Mutex::unlock($gMessageLock);
  48. }
  49. }
  50. function handler_redis($redis, $chan, $msg)
  51. {
  52. Log::record("message: {$chan} -- {$msg}",Log::DEBUG);
  53. $cur_trd = Thread::getCurrentThread();
  54. $cur_trd->dispatch($chan,$msg);
  55. }
  56. function all_channels()
  57. {
  58. return array('ch_index');
  59. }