使用php-PhantomJS循环页面请求时的响应408

时间:2016-09-30 11:38:58

标签: php symfony php-phantomjs

我正在尝试使用Symfony测试平均页面加载时间,使用PhantomJS php引擎发送请求。为什么有些页面有一半时间我收到408响应,只有一半 - 200?是否还需要一些延迟或选项?

public function loadPage($thePage){

    $testResults = [];
    $errorCount = 0;
    $statusCodes = [];

    $client = Client::getInstance();
    $upOne = realpath(__DIR__ . '/../../..');
    $client->getEngine()->setPath($upOne.'/bin/phantomjs');

    $client->getEngine()->addOption('--load-images=true');
    $client->getEngine()->addOption('--ignore-ssl-errors=true');

    $client->isLazy();

        $request = $client->getMessageFactory()->createRequest($thePage, 'GET');
        $request->setTimeout(10000);

        $response = $client->getMessageFactory()->createResponse();

        for($i = 0; $i < 10; $i++) {

            $startScriptTime = microtime(TRUE);

            $client->send($request, $response);

                if($response->getStatus() !== 200) {

                    $errorCount++;
                }

            $endScriptTime = microtime(TRUE);
            $totalScriptTime = $endScriptTime - $startScriptTime;
            $loadTime = number_format($totalScriptTime, 4);

            $statusCodes[] = [$response->getStatus(), $loadTime];

            if($response->getStatus() == 200){
                $testResults[] = $loadTime;
            }
        }

    $outcome = [$this->getAverageNoExtremes($testResults), $errorCount, $statusCodes];
    return $outcome;
}

0 个答案:

没有答案