public function testElapsedStartStop() { $this->stopWatch->start(); usleep(2500); $this->stopWatch->stop(); $elapsed = $this->stopWatch->getElapsedMilliseconds(); $this->assertGreaterThanOrEqual(2, $elapsed); $this->assertLessThan(10, $elapsed); $elapsedSeconds = $this->stopWatch->getElapsedSeconds(); $this->assertGreaterThanOrEqual(0.002, $elapsedSeconds); $this->assertLessThan(0.01, $elapsedSeconds); $elapsedMicroseconds = $this->stopWatch->getElapsedMicroseconds(); $this->assertGreaterThanOrEqual(2000, $elapsedMicroseconds); $this->assertLessThan(10000, $elapsedMicroseconds); }
$watch = new Stopwatch(); $watch->Start(); // 直接发送 foreach ($wbs as $type) { $type_arr = explode('|', $type); $third = $thirdAccount->getByType($type_arr[0], $type_arr[1]); $api = Factory::CreateAPI2($type_arr[0], $type_arr[1], $third); $ret = $api->publish($_POST['title'], $content); if ($ret !== true && str_contains($ret, '已过期')) { $thirdAccount->fail($third, $ret); } $TEMPLATE['report'][$type] = array('status' => $ret === true, 'msg' => $ret === true ? '发送成功!' . ($third['url'] ? '<a href="' . $third['url'] . '" target="_blank">查看</a>' : '') : '发送失败:' . $ret . ' <a href="list_err.php">重新发送</a>'); $task->AddTask($type, $content, time(), NULL, $ret === true ? Task::OK : Task::ERROR, $ret, 'blog', $_POST['title']); } $watch->Stop(); $TEMPLATE['report']['watch'] = array('status' => true, 'msg' => "总耗时:{$watch->getElapsedSeconds()} 秒"); } } } $TEMPLATE['title'] = '发博客'; $TEMPLATE['login_name'] = Passport::GetLoginName(); $TEMPLATE['nav']['blog'] = 'current'; $TEMPLATE['target_list'] = $wt_open->getBlogList(); $TEMPLATE['platform_list'] = $wt_open->getPlatformList(); foreach ($TEMPLATE['platform_list'] as &$item) { $item['list'] = $wt_open->getBlogList($item['id']); unset($item); } $smarty = new Template(); echo $smarty->r('blog'); function validate()
if (str_contains($item['msg'], '重复发送') || str_contains($item['msg'], '用户调用次数超过限制')) { $task->update(array('retry_count' => Task::RETRY_COUNT), array('id' => $id)); continue; } $third = $thirdAccount->getThird($item['uid'], $type_arr[0], $type_arr[1]); if ($third && $third['valid'] == 1) { $api = Factory::CreateAPI2($type_arr[0], $type_arr[1], $third); if ($item['cat'] == 'weibo') { $ret = $api->upload($item['content'], $item['pic']); } else { $ret = $api->publish($item['title'], $item['content']); } } else { $ret = $third ? '账号绑定过期,尚未重新绑定' : '账号绑定已取消'; } if ($ret === true) { $task->UpdateStatus(Task::OK, $id); echo "任务#{$id}:发送成功<br>\r\n"; } else { if (str_contains($ret, '已过期')) { $thirdAccount->fail($third, $ret); } $task->UpdateStatus(Task::ERROR, $id, $ret); echo "任务#{$id}:发送失败:{$ret}<br>\r\n"; } usleep(500 * 1000); } $watch->Stop(); $count = count($tasks); echo "共{$count}个任务,总耗时:{$watch->getElapsedSeconds()} 秒<br>\r\n"; echo "\r\nOK";