Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

163
Vistas
Streaming file through php server from amazon s3

I would like to stream a file from S3 to the client browser using PHP. I could manage to do it but I have a problem with large files. First, it takes all the memory available for the session and end up with a "Memory exhausted" error. Second, when reaching "fread(...)" for the first time, it hangs almost 1 min for a 50Mo file before to start sending to the browser. How can I handle these 2 problems? Here is my code.

$client->register_stream_wrapper();

    if($stream = fopen('s3://' . S3_BUCKET . '/' . $destination_s3, 'r'))
    {
        //Send file to browser.
        header("Cache-Control: no-store, no-cache, must-revalidate");
        header("Cache-Control: post-check=0, pre-check=0", false);
        header("Cache-control: no-store");
        header("Pragma: no-cache");
        header("Content-Disposition: attachment; filename=$file_name");
        header("Content-Type: " . $file_type);
        while (!feof($stream)) {
            echo fread($stream, 1024);
            flush();
        }
        fclose($stream);
    }
about 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda