Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. function loadEventAll($uid=0){
  2. if (isset($_POST['event_log'])){
  3. $event_log = json_decode($_POST['event_log']); //here event already worked on page
  4. }
  5. else $event_log = array();
  6. for($i=0;$i<25;$i++){
  7. $now = time();
  8. $time = $now;//-$this->triggered_timeout;
  9.  
  10. //sql to cut already worked event
  11. $noid = array();
  12. foreach($event_log as $eve){
  13. if(isset($eve->id)) $noid[] = 'id<>'.$eve->id;
  14. }
  15. if (count($noid)) $noid = ' AND ('.implode(' AND ', $noid).') ';
  16. else $noid = '';
  17.  
  18. //don't try to understand this :)
  19. $q="SELECT * FROM ig_event WHERE (user_id='$uid' OR user_id=0) AND (((triggered+2>=$time OR triggered=0) AND infinite=0) OR (infinite=1 AND triggered+10<=$time)) AND ($now<time_end or infinite=1) AND time_start<=$time $noid";
  20. $link = mysql_query($q);
  21. $arr = array();
  22. if(!$link){
  23. sleep(1);
  24. continue; // if no event occurring start next iteration
  25. }
  26. if (mysql_num_rows($link)){
  27. while ($ddd = mysql_fetch_assoc($link)){
  28. $id = $ddd['id'];
  29. if ($ddd['direct_call']!=""){ //call js function on page
  30. $arr[] = $ddd['direct_call'].':'.$id.':'.$ddd['param'];
  31.  
  32. if ($ddd['success']!=1){
  33. if (!$ddd['infinite']) $succ = ' success=1';else $succ='';
  34. $ctime = time();
  35. $q = "UPDATE ig_event SET $succ,triggered='$ctime' WHERE id='$id'";
  36. mysql_query($q);
  37. }
  38. }
  39. else{ // usually not used
  40. if ($this->load->module($ddd['module'])){
  41. if (method_exists($this->$ddd['module'], $ddd['action'])){
  42.  
  43. $time = time();
  44. if (($tarr = $this->$ddd['module']->$ddd['action']($ddd['param'])) and !$ddd['infinite']){
  45. $q = "UPDATE ig_event SET success=1 WHERE id='$id'";
  46. mysql_query($q);
  47. }
  48. }
  49. else{
  50. $q = "UPDATE ig_event SET success=1 WHERE id='$id'";
  51. mysql_query($q);
  52. }
  53. $q = "UPDATE ig_event SET triggered='$time' WHERE id='$id'";
  54. mysql_query($q);
  55. if (!$ddd['infinite']) $arr[] = 'blank'.':'.$id.':';
  56. }
  57. }
  58. }
  59. return $arr;
  60. }
  61. sleep(1);
  62. }
  63. return $arr;
  64. }
  65.  
  66. id | col1 | col2 | timestamp
  67. ------------------------------
  68. 1 | herp | derp | 1347373151
  69. 2 | herp | derp | 1347373152
  70. 3 | herp | derp | 1347373153
  71.  
  72. $q = "SELECT * FROM `table` WHERE `timestamp` < ".$lastCaughtEventTime;
  73.  
  74. function poll() {
  75. $results = [];
  76. $start = microtime(true);
  77. $q = "SELECT * FROM `table` WHERE `timestamp` < " . (int) $_POST['timestamp'];
  78. while (true) {
  79. $result = mysql_query($q);
  80. if (mysql_num_rows($result) > 0) {
  81. $result = returnResults($result);
  82. break;
  83. }
  84. else {
  85. if (time() - $start > POLLING_TIMEOUT) {
  86. die('timeout');
  87. }
  88. sleep(2);
  89. }
  90. }
  91. echo json_encode($result);
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement