Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

162
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda