The best method to send a large file to client?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • howachen@gmail.com

    The best method to send a large file to client?

    I have many text file with 1 to 2MB in size

    currently, i use the method:

    echo file_get_conten ts( $file_path );


    are there any better method?

    thanks.

  • .:[ ikciu ]:.

    #2
    Re: The best method to send a large file to client?

    Hmm Uzytkownik <howachen@gmail .comwrote:
    are there any better method?

    ofc, you can gzip this file first you will send few kB not mB

    --
    ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~
    Ikciu | gg: 718845 | yahoo: ikciu_irsa | www: www.e-irsa.pl

    2be || !2be $this =mysql_query();


    Comment

    • .:[ ikciu ]:.

      #3
      Re: The best method to send a large file to client?

      Hmm Uzytkownik <howachen@gmail .comwrote:
      I have many text file with 1 to 2MB in size
      what you mean send? send via email, send via browser or what?

      --
      ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~
      Ikciu | gg: 718845 | yahoo: ikciu_irsa | www: www.e-irsa.pl

      2be || !2be $this =mysql_query();


      Comment

      • howachen@gmail.com

        #4
        Re: The best method to send a large file to client?


        ..:[ ikciu ]:. 寫道:
        Hmm Uzytkownik <howachen@gmail .comwrote:
        I have many text file with 1 to 2MB in size
        >
        what you mean send? send via email, send via browser or what?
        >
        --
        ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~
        Ikciu | gg: 718845 | yahoo: ikciu_irsa | www: www.e-irsa.pl
        >
        2be || !2be $this =mysql_query();
        i mean read the content from the text file, and send to the browser

        Comment

        • howachen@gmail.com

          #5
          Re: The best method to send a large file to client?


          howachen@gmail. com 寫道:
          I have many text file with 1 to 2MB in size
          >
          currently, i use the method:
          >
          echo file_get_conten ts( $file_path );
          >
          >
          are there any better method?
          >
          thanks.
          gzip take time, if many people access the page, my server will be
          killed....

          what i want to look for is if any method can send the file to apache
          for display with getting back the content to the php first, i.e. i want
          streaming, no matter the size of the file, even 1GB

          echo file_get_conten ts( $file_path ); // no good, as content will be
          passed back in the STACK during function call

          // i want sth like...streamin g
          print_file_to_c lient( $file_path );

          Comment

          • Arjen

            #6
            Re: The best method to send a large file to client?

            howachen@gmail. com schreef:
            I have many text file with 1 to 2MB in size
            >
            currently, i use the method:
            >
            echo file_get_conten ts( $file_path );
            >
            >
            are there any better method?
            >
            thanks.
            Yup .. stream the file.

            file($file_path );

            foreach($file as $line)
            {
            echo $line;
            ob_flush();
            flush();
            }

            Arjen

            Comment

            • Arkady Renko

              #7
              Re: The best method to send a large file to client?

              howachen@gmail. com wrote:
              howachen@gmail. com 寫道:
              >I have many text file with 1 to 2MB in size
              >>
              >currently, i use the method:
              >>
              >echo file_get_conten ts( $file_path );
              >>
              >>
              >are there any better method?
              >>
              >thanks.
              gzip take time, if many people access the page, my server will be
              killed....

              what i want to look for is if any method can send the file to apache
              for display with getting back the content to the php first, i.e. i want
              streaming, no matter the size of the file, even 1GB

              echo file_get_conten ts( $file_path ); // no good, as content will be
              passed back in the STACK during function call

              // i want sth like...streamin g
              print_file_to_c lient( $file_path );
              If you want to stream the file (without compressing it) then why not use
              fread to read small "chunks" of the file?

              Something like this...

              $chunk = (8024);
              $buffer = '';
              $handle = fopen($filename , 'rb');
              if ($handle === false) die();
              while (!feof($handle) )
              {
              $buffer = fread($handle, $chunk);
              print $buffer;
              flush();
              ob_flush();
              }
              fclose ($handle);



              -- -------------------- Arkady Renko Network Admin To email me directly
              Remove all capitals and underscores from my posting address

              Comment

              • .:[ ikciu ]:.

                #8
                Re: The best method to send a large file to client?

                Hmm U¿ytkownik <howachen@gmail .comwrote:
                gzip take time, if many people access the page, my server will be
                killed....
                you right, i thought you send it via mail or allow user to download it, when
                you only display it you you can use require function (but you have right
                there is no php code or just show it like a data)


                --
                ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~
                Ikciu | gg: 718845 | yahoo: ikciu_irsa | www: www.e-irsa.pl

                2be || !2be $this =mysql_query();


                Comment

                • _q_u_a_m_i_s's

                  #9
                  Re: The best method to send a large file to client?

                  why don't u use readfile()? http://ro2.php.net/readfile
                  it does exactly what you want, and is much faster than reading the file
                  and echo'ing it

                  ..:[ ikciu ]:. a scris:
                  Hmm U¿ytkownik <howachen@gmail .comwrote:
                  gzip take time, if many people access the page, my server will be
                  killed....
                  >
                  you right, i thought you send it via mail or allow user to download it, when
                  you only display it you you can use require function (but you have right
                  there is no php code or just show it like a data)
                  >
                  >
                  --
                  ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~
                  Ikciu | gg: 718845 | yahoo: ikciu_irsa | www: www.e-irsa.pl

                  2be || !2be $this =mysql_query();

                  Comment

                  • NC

                    #10
                    Re: The best method to send a large file to client?

                    On Oct 5, 12:17 am, howac...@gmail. com wrote:
                    >
                    I have many text file with 1 to 2MB in size
                    >
                    currently, i use the method:
                    >
                    echo file_get_conten ts( $file_path );
                    >
                    are there any better method?
                    Yes. Use readfile():



                    Cheers,
                    NC

                    Comment

                    • Colin McKinnon

                      #11
                      Re: The best method to send a large file to client?

                      Arjen wrote:
                      howachen@gmail. com schreef:
                      >I have many text file with 1 to 2MB in size
                      >>
                      >currently, i use the method:
                      >>
                      >echo file_get_conten ts( $file_path );
                      >>
                      >>
                      >are there any better method?
                      >>
                      >thanks.
                      >
                      Yup .. stream the file.
                      >
                      file($file_path );
                      You'll run out of memory very quickly using file(...) or
                      file_get_conten ts(...) on big files.

                      C.

                      Comment

                      • howachen@gmail.com

                        #12
                        Re: The best method to send a large file to client?


                        NC 寫道:
                        On Oct 5, 12:17 am, howac...@gmail. com wrote:

                        I have many text file with 1 to 2MB in size

                        currently, i use the method:

                        echo file_get_conten ts( $file_path );

                        are there any better method?
                        >
                        Yes. Use readfile():
                        >


                        Cheers,
                        NC
                        thanks all...

                        seems readfile() is the best method

                        Comment

                        • R. Rajesh Jeba Anbiah

                          #13
                          |OT| Re: The best method to send a large file to client?

                          NC wrote:
                          On Oct 5, 12:17 am, howac...@gmail. com wrote:

                          I have many text file with 1 to 2MB in size

                          currently, i use the method:

                          echo file_get_conten ts( $file_path );

                          are there any better method?
                          >
                          Yes. Use readfile():
                          >
                          http://www.php.net/readfile
                          When I read the responses in this thread, I was wondering what
                          happened to c.l.php (obvious shortage of PHP saints). Fortunately,
                          still Nikolai Chuvakhin is hacking PHP...:-)

                          --
                          <?php echo 'Just another PHP saint'; ?>
                          Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

                          Comment

                          Working...