syncAll.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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_Offer::class,
  15. Sync_Game::class,
  16. ];
  17. if ($index == 0) {
  18. CallLog::setUrl('Sync_Base');
  19. for ($i = 0; $i < 10000; $i++) {
  20. $time = microtime(true);
  21. foreach ($classList as $className) {
  22. $obj = getObj($className);
  23. $flag = $obj->isTimeout($time);
  24. if ($flag) {
  25. // 时间到了,就通知一下他们拉取数据
  26. $obj->pubSubscribe(false);
  27. }
  28. }
  29. Tool::sleep(1);
  30. }
  31. } else {
  32. CallLog::setUrl($classList[$index - 1]);
  33. $objSync = getObj($classList[$index - 1]);
  34. $objSync->syncDaemon();
  35. }
  36. /**
  37. * Sync_Base 对象初始化
  38. * @return Sync_Base DB对象
  39. */
  40. function getObj($className) {
  41. global $map;
  42. if (!$map[$className]) {
  43. $map[$className] = new $className();
  44. }
  45. return $map[$className];
  46. }