public function testArrays() { $total = 1000000; $try1 = array_fill(0, $total, 1); $try1[rand(0, count($try1) - 1)] = null; $try2 = array_fill(0, $total, 1); $try2[rand(0, count($try1) - 1)] = null; $try2[(string) count($try2)] = 'value'; $uk = rand(0, $total); unset($try2[$uk]); print 'isSequentialFastest:' . PHP_EOL; \PHP_Timer::start(); $isHashFalse = !ArrayStructure::isSequentialFastest($try1); $time = \PHP_Timer::stop(); print \PHP_Timer::secondsToTimeString($time) . PHP_EOL; \PHP_Timer::start(); $isHashTrue = !ArrayStructure::isSequentialFastest($try2); $time = \PHP_Timer::stop(); print \PHP_Timer::secondsToTimeString($time) . PHP_EOL; $this->assertFalse($isHashFalse); $this->assertTrue($isHashTrue); print 'isSequentialSimple:' . PHP_EOL; \PHP_Timer::start(); $isSeqFalse = !ArrayStructure::isSequentialSimple($try1); $time = \PHP_Timer::stop(); print \PHP_Timer::secondsToTimeString($time) . PHP_EOL; \PHP_Timer::start(); $isSeqTrue = !ArrayStructure::isSequentialSimple($try2); $time = \PHP_Timer::stop(); print \PHP_Timer::secondsToTimeString($time) . PHP_EOL; $this->assertFalse($isSeqFalse); $this->assertTrue($isSeqTrue); print 'isSequentialExotic:' . PHP_EOL; \PHP_Timer::start(); $isSeqTrue = ArrayStructure::isSequentialExotic($try1); $time = \PHP_Timer::stop(); print \PHP_Timer::secondsToTimeString($time) . PHP_EOL; \PHP_Timer::start(); $isSeqFalse = ArrayStructure::isSequentialExotic($try2); $time = \PHP_Timer::stop(); print \PHP_Timer::secondsToTimeString($time) . PHP_EOL; $this->assertFalse($isSeqFalse); $this->assertTrue($isSeqTrue); print 'isAssoc:' . PHP_EOL; \PHP_Timer::start(); $isAssocFalse = ArrayStructure::isAssoc($try1); $time = \PHP_Timer::stop(); print \PHP_Timer::secondsToTimeString($time) . PHP_EOL; \PHP_Timer::start(); $isAssocTrue = ArrayStructure::isAssoc($try2); $time = \PHP_Timer::stop(); print \PHP_Timer::secondsToTimeString($time) . PHP_EOL; $this->assertFalse($isAssocFalse); $this->assertTrue($isAssocTrue); }
/** * @covers PHP_Timer::secondsToTimeString */ public function testSecondsToTimeString() { $this->assertEquals('0 seconds', PHP_Timer::secondsToTimeString(0)); $this->assertEquals('1 second', PHP_Timer::secondsToTimeString(1)); $this->assertEquals('2 seconds', PHP_Timer::secondsToTimeString(2)); $this->assertEquals('01:00', PHP_Timer::secondsToTimeString(60)); $this->assertEquals('01:01', PHP_Timer::secondsToTimeString(61)); $this->assertEquals('02:00', PHP_Timer::secondsToTimeString(120)); $this->assertEquals('02:01', PHP_Timer::secondsToTimeString(121)); $this->assertEquals('01:00:00', PHP_Timer::secondsToTimeString(3600)); $this->assertEquals('01:00:01', PHP_Timer::secondsToTimeString(3601)); }
function podlove_validate_image_cache() { set_time_limit(5 * MINUTE_IN_SECONDS); PHP_Timer::start(); $cache_files = glob(trailingslashit(Image::cache_dir()) . "*" . DIRECTORY_SEPARATOR . "*" . DIRECTORY_SEPARATOR . "cache.yml"); foreach ($cache_files as $cache_file) { $cache = Yaml::parse(file_get_contents($cache_file)); $validator = new HttpHeaderValidator($cache['source'], $cache['etag'], $cache['last-modified']); $validator->validate(); if ($validator->hasChanged()) { wp_schedule_single_event(time(), 'podlove_refetch_cached_image', [$cache['source'], $cache['filename']]); } } $time = PHP_Timer::stop(); \Podlove\Log::get()->addInfo(sprintf('Finished validating %d images in %s', count($cache_files), PHP_Timer::secondsToTimeString($time))); }
<?php use Peridot\Concurrency\Runner\StreamSelect\IO\JobInfo; describe('JobInfo', function () { beforeEach(function () { $this->info = new JobInfo('/path/to/file.php'); $this->info->end = microtime(true); }); describe('->getTimeElapsed()', function () { it('should return a formatted time string', function () { $formatted = PHP_Timer::secondsToTimeString($this->info->end - $this->info->start); expect($this->info->getTimeElapsed())->to->equal($formatted); }); }); });
/** * Invoked by pcntl_signal() when a SIGALRM occurs. */ public function callback() { throw new PHP_Invoker_TimeoutException(sprintf('Execution aborted after %s', PHP_Timer::secondsToTimeString($this->timeout))); }
/** * Output result footer */ public function footer() { $this->output->write($this->color('success', sprintf("\n %d passing", $this->passing))); $this->output->writeln(sprintf($this->color('muted', " (%s)"), \PHP_Timer::secondsToTimeString($this->getTime()))); if (!empty($this->errors)) { $this->output->writeln($this->color('error', sprintf(" %d failing", count($this->errors)))); } if ($this->pending) { $this->output->writeln($this->color('pending', sprintf(" %d pending", $this->pending))); } $this->output->writeln(""); $errorCount = count($this->errors); for ($i = 0; $i < $errorCount; $i++) { list($test, $error) = $this->errors[$i]; $this->outputError($i + 1, $test, $error); } }
* User: Jiang Yu * Date: 2015/06/30 * Time: 3:37 PM. */ use Worker\EndlessTasks; require __DIR__ . '/../bootstrap.php'; $fireNotifications = function ($jsonArray) { $requestFactory = new \Worker\Model\TaskFactory(); $tasks = []; foreach ($jsonArray as $jsonString) { $options = json_decode($jsonString, true); if (!is_array($options)) { continue; } $tasks[] = $requestFactory->create($options[CURLOPT_URL], $options); } PHP_Timer::start(); $worker = new \Worker\CurlWorker(); $worker->addTasks($tasks); $worker->run(); $delta = PHP_Timer::stop(); echo PHP_Timer::resourceUsage() . ' fire notif cost: ' . PHP_Timer::secondsToTimeString($delta) . PHP_EOL; }; $facebookOptions = \Application\Facade::getInstance()->getFBGatewayOptions(); dump($facebookOptions); $taskGenerator = new EndlessTasks($facebookOptions['queueLocation']); $bufferedNotifications = $taskGenerator->get(); /** @var string[] $tasks */ foreach ($bufferedNotifications as $tasks) { call_user_func($fireNotifications, $tasks); }
} $this->exception = $exception; $this->emitter->emit('test.passed', [new Test('passing test', function () { })]); $this->emitter->emit('test.failed', [new Test('failing test', function () { }), $this->exception]); $this->emitter->emit('test.pending', [new Test('pending test', function () { })]); $this->footer = $this->reporter->footer(); $this->contents = $this->output->fetch(); }); it('should output success text', function () { assert(strstr($this->contents, '1 passing') !== false, 'should contain passing text'); }); it('should output time', function () { $time = PHP_Timer::secondsToTimeString($this->reporter->getTime()); assert(strstr($this->contents, $time) !== false, 'should contain time text'); }); it('should output failure text', function () { assert(strstr($this->contents, '1 failing') !== false, 'should contain failure text'); }); it('should output pending count', function () { assert(strstr($this->contents, '1 pending') !== false, 'should contain pending text'); }); it('should display exception stacks and messages', function () { $expectedExceptionMessage = " ooops" . PHP_EOL . " nextline"; assert(strstr($this->contents, $expectedExceptionMessage) !== false, "should include exception message"); $trace = preg_replace('/^#/m', " #", $this->exception->getTraceAsString()); assert(strstr($this->contents, $trace) !== false, "should include exception stack"); }); });
<hr> <small> <?php if (isset($hasControllerActionTime)) { ?> <div>Controller Action Execution Time: <?php echo PHP_Timer::secondsToTimeString(PHP_Timer::stop()); ?> </div> <?php } ?> <div>Execution Time: <?php echo PHP_Timer::timeSinceStartOfRequest(); ?> </div> <?php if (isset($bootstrapTime)) { ?> <div>Application Bootstrap Time: <?php echo $bootstrapTime; ?> </div> <?php } ?> <?php
$stepGenerator = WorkRoundGenerator::generate($now, $quitTimestamp, $interval, false); foreach ($stepGenerator as $timestamp) { $msg = $myself . ': ' . date('c', $timestamp) . ' run with ts ' . date('c', $timestamp); appendLog($msg); $date = $specifiedDate ? $specifiedDate : date('Y-m-d'); $groupedUidList = $installUidProvider->generate($date, function ($shardId, $userCount, $delta) { if ($userCount === 0) { return; } appendLog(sprintf('%s install(%d) cost %s', $shardId, $userCount, PHP_Timer::secondsToTimeString($delta))); }); $queue->push($groupedUidList); $deltaList = $installUidProvider->getDeltaList(); $totalCount = 0; foreach ($groupedUidList as $shardId => $shardUidList) { $shardCount = count($shardUidList); if ($shardCount === 0) { continue; } $totalCount += $shardCount; } appendLog(sprintf('%s: %s found %d install user, cost %s', $myself, date('c'), $totalCount, PHP_Timer::secondsToTimeString(array_sum($deltaList)))); $logFile = call_user_func($logFileGetter, $gameVersion, $date); file_put_contents($logFile, date('c') . ' have ' . $totalCount . PHP_EOL . print_r($groupedUidList, true)); if ($specifiedDate) { dump(date('c')); dump($groupedUidList); dump($myself . ': quit'); break; } }
/** * Output test stats. If any errors were written to stderr at any point, then * they will be dumped here. * * @param array $errors * @return void */ public function onConcurrentRunnerEnd($errors) { $this->output->writeln(sprintf(' Run time: %s', \PHP_Timer::secondsToTimeString($this->getTime()))); $errorCount = count($errors); if (!$errorCount) { return; } $labels = ['was', 'error']; if ($errorCount > 1) { $labels = ['were', 'errors']; } $this->output->writeln(''); $this->output->writeln($this->color('error', sprintf('There %s %d %s:', $labels[0], $errorCount, $labels[1]))); $this->outputErrors($errors); }
/** * @param Platform $platform * @param DeAuthorizedUserQuery $query * * @return array * @throws Exception */ protected function findDeAuthorizedUser(Platform $platform, DeAuthorizedUserQuery $query) { $resultSet = []; $shardList = $platform->getMySQLShards(); foreach ($shardList as $shardConfig) { $dbName = $shardConfig['database']; appendLog('on database ' . $dbName); PHP_Timer::start(); $snsidList = $this->onShard($shardConfig, $query); $delta = PHP_Timer::stop(); appendLog('cost on database ' . $dbName . ': ' . PHP_Timer::secondsToTimeString($delta)); dump(sprintf('Memory: %4.2fMb', memory_get_peak_usage(true) / 1048576)); $resultSet = array_merge($resultSet, $snsidList); } return $resultSet; }
/** * The time elapsed on the job as a formatted time * string. * * @return string */ public function getTimeElapsed() { return \PHP_Timer::secondsToTimeString($this->end - $this->start); }
} else { assert(isset($options['gv']), 'game version not defined'); $gameVersion = trim($options['gv']); } $esHost = isset($options['es']) ? $options['es'] : '52.19.73.190'; assert(isset($options['uid']), 'uid not defined'); $uid = trim($options['uid']); $msg = sprintf('game version: %s, ES host: %s, uid: %s', $gameVersion, $esHost, $uid); $verbose && dump($msg); $provider = new UserDetailProvider($gameVersion, PdoFactory::makePool($gameVersion)); $groupedUserList = array_filter($provider->find([$uid])); if ($verbose) { dump(__FILE__); dump($groupedUserList); } $indexer = IndexerFactory::make($esHost, $gameVersion); foreach ($groupedUserList as $shardId => $shardUserList) { $delta = $indexer->batchUpdate($shardUserList); $batchResult = $indexer->getBatchResult(); dump(__FILE__); array_map(function ($errorString) { $decoded = json_decode($errorString, true); if (is_array($decoded)) { dump($decoded); } else { dump($errorString); } }, $batchResult); // dump($indexer->getLastRoundData()); dump('cost ' . PHP_Timer::secondsToTimeString($delta[0])); }
$arr = explode('/', parse_url($url, PHP_URL_PATH)); return (string) $arr[3]; } $snsidList = ['100001349218797', '675097095878591', '675097095878592', '675097095878593', '675097095878594']; $taskFactory = new \Worker\Model\TaskFactory(); $tasks = array_map(function ($snsid) use($taskFactory) { $url = sprintf('http://52.19.73.190:9200/farm/user:tw/%s/_update', $snsid); $postData = sprintf('{"doc":{"status":"%d"}}', time()); return $taskFactory->create($url, [CURLOPT_URL => $url, CURLOPT_POST => 1, CURLOPT_POSTFIELDS => $postData, CURLOPT_RETURNTRANSFER => 1]); }, $snsidList); //dump($tasks); PHP_Timer::start(); $curlWorker = new \Worker\CurlWorker(new \Worker\Queue\HttpTracer()); $curlWorker->addTasks($tasks); $responseList = []; $trace = $curlWorker->run($responseList, function () { echo microtime(true) . ' got response' . PHP_EOL; }); $taskWallTime = PHP_Timer::stop(); array_walk($responseList, function (array $response) { dump(['url' => $response['url'], 'http_code' => $response['http_code'], 'content' => $response['content']]); }); $httpCost = 0; array_walk($trace, function (\Worker\Queue\HttpTracer $httpTracer, $url) use(&$httpCost) { $httpCost += $httpTracer->getElapsedTime(); dump(parseSnsid($url) . ' => ' . $httpTracer); }); dump('time cost on http: ' . PHP_Timer::secondsToTimeString($httpCost)); dump('wall time on http: ' . PHP_Timer::secondsToTimeString($taskWallTime)); dump('Run time: ' . PHP_Timer::timeSinceStartOfRequest()); dump(sprintf('Memory: %4.2fMb', memory_get_peak_usage(true) / 1048576));
/** * @covers PHP_Timer::secondsToTimeString * @dataProvider secondsProvider */ public function testSecondsToTimeString($string, $seconds) { $this->assertEquals($string, PHP_Timer::secondsToTimeString($seconds)); }
print SearchFactory::find('http://api.travelpayouts.com/data/airports.json ', 'Puklovo', 1, false)->fetchOne()['en'] . PHP_EOL; } catch (\Exception $ex) { $exp->push($ex); try { $exp->saveToDisk($ex); } catch (\Exception $e) { print sprintf('Exception in %s, in %s line with message %s', $e->getFile(), $e->getLine(), $e->getMessage()); } } /** * {"code":"MOW","name":"Moscow", * "coordinates":{"lon":37.617633,"lat":55.755786},"time_zone":"Europe\/Moscow","name_translations": * {"de":"Moskau","en":"Moscow","zh-CN":"\u83ab\u65af\u79d1","tr":"Moscow", * "ru":"\u041c\u043e\u0441\u043a\u0432\u0430","it":"Mosca","es":"Mosc\u00fa","fr":"Moscou", * "th":"\u0e21\u0e2d\u0e2a\u0e42\u0e01"},"country_code":"RU"} */ /** * Oh God, bug. Cyclic recursion. In the process of repair. */ // print SearchFactory::find( //'http://api.rottentomatoes.com/api/public/v1.0/movies.json?apikey=42r4rbkmpe3bm7ny68n9qvzj&q= //Iron&page_limit=5&page=1', // 'Iron', // 1, // true, // true, // 'dev' // )->fetchOne() . PHP_EOL; $time = \PHP_Timer::stop(); print \PHP_Timer::secondsToTimeString($time);
/** * Runs a TestCase. * * @param PHPUnit_Framework_Test $test */ public function run(PHPUnit_Framework_Test $test) { PHPUnit_Framework_Assert::resetCount(); $error = FALSE; $failure = FALSE; $incomplete = FALSE; $skipped = FALSE; $timeout = FALSE; $this->startTest($test); $errorHandlerSet = FALSE; if ($this->convertErrorsToExceptions) { $oldErrorHandler = set_error_handler(array('PHPUnit_Util_ErrorHandler', 'handleError'), E_ALL | E_STRICT); if ($oldErrorHandler === NULL) { $errorHandlerSet = TRUE; } else { restore_error_handler(); } } if (self::$xdebugLoaded === NULL) { self::$xdebugLoaded = extension_loaded('xdebug'); self::$useXdebug = self::$xdebugLoaded; } $useXdebug = self::$useXdebug && $this->codeCoverage !== NULL && !$test instanceof PHPUnit_Extensions_SeleniumTestCase && !$test instanceof PHPUnit_Framework_Warning; if ($useXdebug) { $this->codeCoverage->start($test); } PHP_Timer::start(); try { if ($this->strictMode && extension_loaded('pcntl')) { switch ($test->getSize()) { case PHPUnit_Util_Test::SMALL: $_timeout = $this->timeoutForSmallTests; break; case PHPUnit_Util_Test::MEDIUM: $_timeout = $this->timeoutForMediumTests; break; case PHPUnit_Util_Test::LARGE: $_timeout = $this->timeoutForLargeTests; break; } $invoker = new PHP_Invoker(); $invoker->invoke(array($test, 'runBare'), array(), $_timeout); } else { $test->runBare(); } } catch (PHPUnit_Framework_AssertionFailedError $e) { $failure = TRUE; if ($e instanceof PHPUnit_Framework_IncompleteTestError) { $incomplete = TRUE; } else { if ($e instanceof PHPUnit_Framework_SkippedTestError) { $skipped = TRUE; } } } catch (PHP_Invoker_TimeoutException $e) { $timeout = TRUE; } catch (Exception $e) { $error = TRUE; } $time = PHP_Timer::stop(); $test->addToAssertionCount(PHPUnit_Framework_Assert::getCount()); if ($this->strictMode && $test->getNumAssertions() == 0) { $incomplete = TRUE; } if ($useXdebug) { try { $this->codeCoverage->stop(!$incomplete && !$skipped); } catch (PHP_CodeCoverage_Exception $cce) { $error = TRUE; if (!isset($e)) { $e = $cce; } } } if ($errorHandlerSet === TRUE) { restore_error_handler(); } if ($error === TRUE) { $this->addError($test, $e, $time); } else { if ($failure === TRUE) { $this->addFailure($test, $e, $time); } else { if ($timeout === TRUE) { $this->addFailure($test, new PHPUnit_Framework_IncompleteTestError(sprintf('Test execution was aborted after %s', PHP_Timer::secondsToTimeString($_timeout))), $time); } else { if ($this->strictMode && $test->getNumAssertions() == 0) { $this->addFailure($test, new PHPUnit_Framework_IncompleteTestError('This test did not perform any assertions'), $time); } else { if ($this->strictMode && $test->hasOutput()) { $this->addFailure($test, new PHPUnit_Framework_OutputError(sprintf('This test printed output: %s', $test->getActualOutput())), $time); } } } } } $this->endTest($test, $time); }
protected function searchDocuments() { dump(__METHOD__); $client = $this->getClient(); $index = $client->getIndex($this->getIndexName()); $type = $index->getType($this->getTypeName()); if (true) { $query = json_decode('{"query":{"bool":{"must":[{"term":{"uid":19246}},{"term":{"name":"XXXXXXXXXX"}},{"term":{"op":30}}],"filter":[{"range":{"level":{"from":10,"to":300}}},{"range":{"addtime":{"gte":"20150706T145200+0800","lte":"20150707T145203+0800"}}}]}}}', true); dump($query); $path = $index->getName() . '/' . $type->getName() . '/_search'; $response = $client->request($path, Request::GET, $query); $this->assertTrue($response->isOk()); // dump($response->getEngineTime()); // dump($response->getQueryTime()); // dump($response->getShardsStatistics()); // dump($response->getStatus()); // http status code // dump($response->getTransferInfo()); dump($response->getData()['hits']['hits']); } if (false) { $search = new Search($client); $search->addIndex($index)->addType($type); $query = new Query\BoolQuery(); // $query->setFrom(0); // $query->setSize(10); // $query->setSort(['uid' => 'asc']); // $query->setFields(['snsid', 'uid']); // $query->setHighlight(['fields' => 'uid']); // $query->setExplain(true); // $term = new Query\Term(['name' => 'XXXXXXXXXX']); // $query->setQuery($term); $query->addMust(new Term(['uid' => 19246])); $query->addMust(new Term(['name' => 'XXXXXXXXXX'])); $query->addMust(new Term(['op' => 30])); // $query->addMustNot(new Term(['country' => 'CN'])); $range = new Query\Range('level', ['from' => 10, 'to' => 300]); $query->addFilter($range); $range = new Query\Range(); $range->addField('addtime', ['gte' => '20150706T145200+0800', 'lte' => '20150707T145203+0800']); $query->addFilter($range); $search->setQuery($query); $resultSet = $search->search(); dump('Hit: ' . $resultSet->count()); $queryArray = $resultSet->getQuery()->toArray(); dump(json_encode($queryArray)); dump($resultSet->getResponse()->getData()['hits']['hits']); dump('query time: ' . \PHP_Timer::secondsToTimeString($resultSet->getResponse()->getQueryTime())); } }
/** * @param string $esHost * @param string $gameVersion * @param int $lastActiveTimestamp */ function main($esHost, $gameVersion, $lastActiveTimestamp) { $dsnList = mysqlDsnGenerator($gameVersion); $totalUserCount = 0; foreach ($dsnList as $mysqlOptions) { $userList = onShard($mysqlOptions, $lastActiveTimestamp); if (count($userList) === 0) { continue; } $totalUserCount += count($userList); PHP_Timer::start(); batchUpdateES($esHost, $gameVersion, $userList); appendLog('ES update[' . count($userList) . '] cost: ' . PHP_Timer::secondsToTimeString(PHP_Timer::stop())); } appendLog(sprintf('%s total user count [%d], from %s', PHP_Timer::resourceUsage(), $totalUserCount, date('Y/m/d H:i:s', $lastActiveTimestamp))); }
$groupedUidList = $installUidProvider->generate($calendarDay, function ($shardId, $userCount, $delta) { if ($userCount === 0) { return; } appendLog(sprintf('%s install(%d) cost %s', $shardId, $userCount, PHP_Timer::secondsToTimeString($delta))); }); $distribution = array_map(function (array $uidList) { return count($uidList); }, $groupedUidList); $newInstallCount = array_sum($distribution); appendLog(sprintf('Total %d new install on %s', $newInstallCount, $calendarDay)); $totalUser += $newInstallCount; $start = microtime(true); $groupedDetail = $userDetailProvider->generate($groupedUidList); $delta = microtime(true) - $start; appendLog(sprintf('Total %d new install on %s, read detail cost %s', $newInstallCount, $calendarDay, PHP_Timer::secondsToTimeString($delta))); $esUpdateQueue = []; foreach ($groupedDetail as $payload) { $shardId = $payload['shardId']; $shardUserList = $payload['dataSet']; $count = count($shardUserList); if ($count === 0) { continue; } appendLog(sprintf('%s have %d user to sync', $shardId, $count)); $esUpdateQueue = array_merge($esUpdateQueue, $shardUserList); $queueLength = count($esUpdateQueue); if ($queueLength >= $magicNumber) { appendLog(sprintf('%s: flush ES update queue: %d user on date %s to sync %s', date('c'), $queueLength, $calendarDay, PHP_Timer::resourceUsage())); call_user_func($esUpdateHandler, $indexer, $esUpdateQueue); $esUpdateQueue = [];
$pdoPool = PdoFactory::makePool($gameVersion); $elasticaHelper = new ElasticaHelper($gameVersion, ELASTIC_SEARCH_INDEX, $magicNumber); $elasticaHelper->setVerbose($verbose); $localeCount = 0; $processedCount = 0; QueryHelperFactory::setVerbose($verbose); $userDetailProvider = new \DataProvider\User\UserDetailProvider($gameVersion, $pdoPool); $shardIdList = $pdoPool->listShardId(); foreach ($shardIdList as $shardId) { $pdo = $pdoPool->getByShardId($shardId); $queryHelper = QueryHelperFactory::make($pdo); PHP_Timer::start(); $uidLocalePairs = $queryHelper->listLocale(); $localeCount += count($uidLocalePairs); appendLog(sprintf('%s have %d locale users cost %s', $shardId, count($uidLocalePairs), PHP_Timer::secondsToTimeString(PHP_Timer::stop()))); file_put_contents(call_user_func($logFileGetter, $gameVersion, $shardId), print_r($uidLocalePairs, true)); $userDetailGenerator = $userDetailProvider->generate([$shardId => array_keys($uidLocalePairs)]); foreach ($userDetailGenerator as $payload) { $userInfoList = $payload['dataSet']; $syncCount = count($userInfoList); $processedCount += $syncCount; appendLog(sprintf('read user info get %d users cost %s', $syncCount, PHP_Timer::resourceUsage())); PHP_Timer::start(); $elasticaHelper->update($userInfoList, function ($snsidList) { appendLog(sprintf('Total %d user sync failed', count($snsidList))); appendLog('failed snsid: ' . implode(',', $snsidList)); }); appendLog(sprintf('Sync %d users to ES cost %s, %s', $syncCount, PHP_Timer::secondsToTimeString(PHP_Timer::stop()), PHP_Timer::resourceUsage())); } } appendLog(sprintf('Total %d locale, %d user processed, cost %s', $localeCount, $processedCount, PHP_Timer::resourceUsage()));