src/History/HttpHistoryArchive.php
public function syncFile($relativeUrl, $forceDownload = false, $allowMissing = false)
    {
        $fs = new Filesystem();

        // Target file to save to will match the relativeUrl being requested, but
        // with the correct directory separator
        $targetFile = str_replace('/', DIRECTORY_SEPARATOR, $relativeUrl);
        $targetFile = $this->storageRoot . $targetFile;

        // Files won't change and are only written after a successful download, so
        // if it exists there's no need to download it again
        if (!$forceDownload && $fs->exists($targetFile)) return $targetFile;

        $tmpFile = $fs->tempnam(sys_get_temp_dir(), 'stellar-sync-tmp');
        $response = $this->httpClient->request('GET', $relativeUrl, [
            'sink' => $tmpFile,
            'http_errors' => false,
        ]);

        // Response succeeded
        if ($response->getStatusCode() == 200) {
            // 200 is always OK
        }
        // 404, but missing files are ok
        elseif ($allowMissing && $response->getStatusCode() == 404) {
            // this is OK
        }
        // Error response or 404 with $allowMissing false
        else {
            throw new \ErrorException(sprintf('HTTP %s: %s', $response->getStatusCode(), $response->getBody()));
        }

        // Move temporary file into its final location
        $fs->mkdir(dirname($targetFile), 0700);
        $fs->rename($tmpFile, $targetFile);

        // Basic rate limiting
        usleep(20000);
        return $targetFile;
    }
public function syncFile($relativeUrl, $forceDownload = false, $allowMissing = false)
    {
        $fs = new Filesystem();

        // Target file to save to will match the relativeUrl being requested, but
        // with the correct directory separator
        $targetFile = str_replace('/', DIRECTORY_SEPARATOR, $relativeUrl);
        $targetFile = $this->storageRoot . $targetFile;

        // Files won't change and are only written after a successful download, so
        // if it exists there's no need to download it again
        if (!$forceDownload && $fs->exists($targetFile)) return $targetFile;

        $tmpFile = $fs->tempnam(sys_get_temp_dir(), 'stellar-sync-tmp');
        $response = $this->httpClient->request('GET', $relativeUrl, [
            'sink' => $tmpFile,
            'http_errors' => false,
        ]);

        // Response succeeded
        if ($response->getStatusCode() == 200) {
            // 200 is always OK
        }
        // 404, but missing files are ok
        elseif ($allowMissing && $response->getStatusCode() == 404) {
            // this is OK
        }
        // Error response or 404 with $allowMissing false
        else {
            throw new \ErrorException(sprintf('HTTP %s: %s', $response->getStatusCode(), $response->getBody()));
        }

        // Move temporary file into its final location
        $fs->mkdir(dirname($targetFile), 0700);
        $fs->rename($tmpFile, $targetFile);

        // Basic rate limiting
        usleep(20000);
        return $targetFile;
    }
Downloads $relativeUrl to the corresponding location on the local filesystem

@param      $relativeUrl
@param bool $forceDownload force download even if the file is present locally
@param bool $allowMissing allow 404 responses
@return string
@throws \ErrorException