syncGroupMessage.php 925 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. /**
  3. * MeeChat to Telegram 消息同步
  4. * @author solu
  5. */
  6. $index = (int) $argv[1];
  7. require_once realpath(dirname(__FILE__)) . '/../common.php';
  8. ini_set("display_errors", "On");
  9. ini_set("default_socket_timeout", -1);
  10. error_reporting(E_ALL & ~E_NOTICE);
  11. $objRedis = dwRedis::init();
  12. $objRedis->setOption(Redis::OPT_READ_TIMEOUT, -1);
  13. for ($i = 0; $i < 100000; $i++) {
  14. _log("step: {$i}");
  15. $msg = Telegram::popMessageList($objRedis);
  16. $msg = json_decode($msg, true);
  17. if (!$msg['chat_id'] || !$msg['text']) {
  18. continue;
  19. }
  20. try {
  21. Telegram::apiRequest("sendMessage", $msg);
  22. } catch (Exception $e) {
  23. _log($e->getMessage());
  24. continue;
  25. }
  26. _log("sendMessage to chat_id:{$msg['chat_id']}");
  27. sleep(0.1);
  28. }
  29. function _log($msg) {
  30. $mem_usage = memory_get_usage(true);
  31. $time = date('Y-m-d H:i:s');
  32. echo "[{$time}][Mem:{$mem_usage}] {$msg}\n";
  33. }