syncAll.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * 同步表数据
  4. * User: ben
  5. * Date: 2018/10/28
  6. * Time: 下午2:08
  7. */
  8. $index = (int) $argv[1];
  9. require_once realpath(dirname(__FILE__)) . '/../common.php';
  10. ini_set("display_errors", "On");
  11. error_reporting(E_ALL & ~E_NOTICE);
  12. $map = [];
  13. $classList = [
  14. Sync_Game::class,
  15. ];
  16. if ($index == 0) {
  17. CallLog::setUrl('Sync_Base');
  18. for ($i = 0; $i < 10000; $i++) {
  19. $time = microtime(true);
  20. foreach ($classList as $className) {
  21. $obj = getObj($className);
  22. $flag = $obj->isTimeout($time);
  23. if ($flag) {
  24. // 时间到了,就通知一下他们拉取数据
  25. $obj->pubSubscribe(false);
  26. }
  27. }
  28. Tool::sleep(1);
  29. }
  30. } else {
  31. CallLog::setUrl($classList[$index - 1]);
  32. $objSync = getObj($classList[$index - 1]);
  33. $objSync->syncDaemon();
  34. }
  35. /**
  36. * Sync_Base 对象初始化
  37. * @return Sync_Base DB对象
  38. */
  39. function getObj($className) {
  40. global $map;
  41. if (!$map[$className]) {
  42. $map[$className] = new $className();
  43. }
  44. return $map[$className];
  45. }