syncAll.php 1.1 KB

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