# SendRemoteFile

The `Sendremotefile` HTTP middleware and the `X-Sendremotefile` HTTP response header are used to stream large files using RoadRunner. Unlike the [X-Sendfile middleware](/docs/http/sendfile.md), `Sendremotefile` allows passing a URL as a header value. While the file is being streamed with the help of RoadRunner, the PHP worker may accept the next request.

The middleware reads the file in 10 MB chunks. For example, for a 5 GB file, only 10 MB of RSS memory is used. If the file is smaller than 10 MB, the middleware adjusts the buffer to fit the file size.

## Configuration

{% code title=".rr.yaml" %}

```yaml
version: "3"

http:
  address: 127.0.0.1:55555
  max_request_size: 1024
  access_logs: false
  middleware: [ "sendremotefile" ]

  pool:
    num_workers: 2
    max_jobs: 0
    allocate_timeout: 60s
    destroy_timeout: 60s
```

{% endcode %}

## Samples

{% code title="worker.php" %}

```php
<?php

use Nyholm\Psr7\Response;
use Spiral\Goridge;
use Spiral\RoadRunner;

ini_set('display_errors', 'stderr');
require __DIR__ . "/vendor/autoload.php";

$worker = new RoadRunner\Worker(new Goridge\StreamRelay(STDIN, STDOUT));
$psr17Factory = new \Nyholm\Psr7\Factory\Psr17Factory();
$psr7 = new RoadRunner\Http\PSR7Worker($worker, $psr17Factory, $psr17Factory, $psr17Factory);

while ($req = $psr7->waitRequest()) {
    try {
        $resp = new Response(
            200,
            ["X-Sendremotefile" => "https://example.com/file.mp4", "Content-Disposition" => "attachment; filename=file.mp4"]
        );

        $psr7->respond($resp);
        unset($resp);
    } catch (\Throwable $e) {
        $psr7->getWorker()->error((string)$e);
    }
}
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.roadrunner.dev/docs/community-plugins/sendremotefile.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
