syncAll.php 1.2 KB

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