Piwik\Http::sendHttpRequest PHP Method

sendHttpRequest() public static method

Sends an HTTP request using best available transport method.
public static sendHttpRequest ( string $aUrl, integer $timeout, string | null $userAgent = null, string | null $destinationPath = null, integer | null $followDepth, boolean $acceptLanguage = false, array | boolean $byteRange = false, boolean $getExtendedInfo = false, string $httpMethod = 'GET', string $httpUsername = null, string $httpPassword = null ) : boolean | string
$aUrl string The target URL.
$timeout integer The number of seconds to wait before aborting the HTTP request.
$userAgent string | null The user agent to use.
$destinationPath string | null If supplied, the HTTP response will be saved to the file specified by this path.
$followDepth integer | null Internal redirect count. Should always pass `null` for this parameter.
$acceptLanguage boolean The value to use for the `'Accept-Language'` HTTP request header.
$byteRange array | boolean For `Range:` header. Should be two element array of bytes, eg, `array(0, 1024)` Doesn't work w/ `fopen` transport method.
$getExtendedInfo boolean If true returns the status code, headers & response, if false just the response.
$httpMethod string The HTTP method to use. Defaults to `'GET'`.
$httpUsername string HTTP Auth username
$httpPassword string HTTP Auth password
return boolean | string If `$destinationPath` is not specified the HTTP response is returned on success. `false` is returned on failure. If `$getExtendedInfo` is `true` and `$destinationPath` is not specified an array with the following information is returned on success: - **status**: the HTTP status code - **headers**: the HTTP headers - **data**: the HTTP response data `false` is still returned on failure.
    public static function sendHttpRequest($aUrl, $timeout, $userAgent = null, $destinationPath = null, $followDepth = 0, $acceptLanguage = false, $byteRange = false, $getExtendedInfo = false, $httpMethod = 'GET', $httpUsername = null, $httpPassword = null)
    {
        // create output file
        $file = self::ensureDestinationDirectoryExists($destinationPath);
        $acceptLanguage = $acceptLanguage ? 'Accept-Language: ' . $acceptLanguage : '';
        return self::sendHttpRequestBy(self::getTransportMethod(), $aUrl, $timeout, $userAgent, $destinationPath, $file, $followDepth, $acceptLanguage, $acceptInvalidSslCertificate = false, $byteRange, $getExtendedInfo, $httpMethod, $httpUsername, $httpPassword);
    }

Usage Example

Example #1
0
 public function testWebArchiving()
 {
     if (self::isMysqli() && self::isTravisCI()) {
         $this->markTestSkipped('Skipping on Mysqli as it randomly fails.');
     }
     $host = Fixture::getRootUrl();
     $token = Fixture::getTokenAuth();
     $urlTmp = Option::get('piwikUrl');
     Option::set('piwikUrl', $host . 'tests/PHPUnit/proxy/index.php');
     $url = $host . 'tests/PHPUnit/proxy/archive.php?token_auth=' . $token;
     $output = Http::sendHttpRequest($url, 600);
     // ignore random build issues
     if (empty($output) || strpos($output, \Piwik\CronArchive::NO_ERROR) === false) {
         $message = "This test has failed. Because it sometimes randomly fails, we skip the test, and ignore this failure.\n";
         $message .= "If you see this message often, or in every build, please investigate as this should only be a random and rare occurence!\n";
         $message .= "\n\narchive web failed: " . $output . "\n\nurl used: {$url}";
         $this->markTestSkipped($message);
     }
     if (!empty($urlTmp)) {
         Option::set('piwikUrl', $urlTmp);
     } else {
         Option::delete('piwikUrl');
     }
     $this->assertContains('Starting Piwik reports archiving...', $output);
     $this->assertContains('Archived website id = 1', $output);
     $this->assertContains('Done archiving!', $output);
     $this->compareArchivePhpOutputAgainstExpected($output);
 }
All Usage Examples Of Piwik\Http::sendHttpRequest