Suppose that I have a resumable link to a URI on the web.Is there any method I can setup a streaming script/service that simply redirects the data by downloading it from a source to destination(assume that the destination is the file requestor) ? Like what happens at .They say that they stream the files directly to end user i.e they DO NOT store any files on their servers.

Dani AI

Generated

Short answer: yes — you can proxy a resumable remote URI to a client without persisting the file. For this means building an HTTP proxy that properly handles resume semantics; 's socket-level idea works, but a higher-level, stream-oriented approach (cURL or PHP streams) is easier to make robust and production-ready.

What you must do (in practice):

  • Accept and inspect the client's Range/If-Range headers and forward them (or equivalent) to the origin.
  • Probe the origin (HEAD) to learn Content-Length, Accept-Ranges and Content-Type so you can mirror the right response headers.
  • When the origin returns a partial payload, return HTTP 206 with a matching Content-Range; otherwise fall back to 200 and note that resume won’t work unless you cache.
  • Stream data in small chunks and flush immediately — do not buffer the whole file in PHP memory. Set set_time_limit(0) and disable output buffering for long transfers.

Example (simplified) — cURL streams directly to the client and forwards the client Range header:

<?php
$source = 'https://remote.example/file.bin';
$ch = curl_init($source);

if (!empty($_SERVER['HTTP_RANGE'])) {
    curl_setopt($ch, CURLOPT_HTTPHEADER, ['Range: ' . $_SERVER['HTTP_RANGE']]);
}

curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
curl_setopt($ch, CURLOPT_BUFFERSIZE, 8192);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_WRITEFUNCTION, function($ch, $data) {
    echo $data;
    flush();
    return strlen($data);
});

curl_exec($ch);
curl_close($ch);

Production notes and cautions: If the origin does not advertise range support you cannot provide true resume without storing data server-side. For scale, prefer offloading to the webserver (nginx reverse-proxy, X-Accel-Redirect / X-Sendfile) or a dedicated proxy — PHP ties up a worker for each stream. Also enforce bandwidth/concurrency limits and verify that proxying that content complies with the origin’s terms of service and copyright rules.

You can open a socket for streaming with fsockopen(),

Then you could use fread() to read it into a $buffer variable and successively pass the data to the user with a:

print $buffer;

command until the EOF marker is found. Make sure to send header() content notifications before trying to pass the user some arbitrary binary data.

The above is just one way to do it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.