Search code examples
phpperformancepassthru

performance of passthru("cat file")


I'm using passthru("cat filepath") in my download script. My concern is that it might use a lot of server resource.

What is the difference between directly link a file in a public directory and download a file using passthru("cat filepath") in php?


Solution

  • What is the difference between directly link a file in a public directory and download a file using passthru("cat filepath") in php?

    The difference is that linking directly to a file does not invoke PHP, while running a PHP script which in turn runs cat causes, well, both PHP and cat to be invoked. This will take up a moderate amount of extra memory, but won't cause server load under most circumstances.

    I was using readfile(), but this function can't be used for files larger than 2gb

    You might want to find a better solution than passing all of the file contents through PHP, in that case. Look into X-Sendfile support in your web server software of choice.