lua_backbround_script_timer.lua 973 B

123456789101112131415161718192021222324252627282930313233343536
  1. -- Declare a shared "timer" counter and functions "timer"
  2. -- and "start" when the script is loading.
  3. shared.timer = 0
  4. function timer()
  5. -- Increment shared value.
  6. shared.timer = shared.timer + 1
  7. -- Return true to keep interval timer running or false to stop.
  8. return true
  9. end
  10. function start()
  11. -- The "start" function is called when the server is ready.
  12. -- At this point, a timer can be created.
  13. mg.set_interval(timer, 5)
  14. end
  15. function stop()
  16. -- The "stop" function is called when the server is stopping.
  17. end
  18. function log(ri)
  19. -- The "log" function can be used to
  20. -- (a) filter messages and return boolean: true (log) or false (do not log)
  21. -- (b) format log message and return it as string (empty string will not log)
  22. -- (c) forward the log data to an external log
  23. -- Example: Log only if the request was not made from localhost
  24. return (ri.remote_addr ~= "127.0.0.1");
  25. end
  26. -- Return false to abort server startup.
  27. return true;