I'm programming something that needs to pressure the download of the file.

I understand the potential of setting the HTTP-headers using PHP after which delivering the file while using readfile-function. However I think this isn't a great way for delivering bigger files since it would need a ton of server performance and also the maximum execution duration of the PHP-scripts could be exceeded.

So can you really send the HTTP-headers using PHP (I must modify them based on records inside a mysql-database.) after which let Apache send the file body? I must include that I possibly could also employ perl scripts however i also don't visit a possibility for carrying this out inside a cgi-script. Thanks.

This can be done strictly with apache when the location and/or filetype from the download is famous in advance:

<Location /downloads>
    SetEnvIf Request_URI ".attachment-extension$" FILENAME=$0
    Header set "Content-disposition" "attachment; filename=%{FILENAME}"
</Location>

since it would need a ton of server performance

I do not believe this is actually the situation. As lengthy as delivering the file towards the client may be the last factor the script does before it terminates, the main difference in CPU/RAM performance between delivering the file from PHP and letting Apache handle it directly ought to be minimal, if there's one whatsoever.

Unless of course you've got a very many Gbps bandwidth in your server by having an incredibly fast Hard disk drive setup, you'd encounter a bandwidth problem lengthy before you decide to went right into a server system assets problem.

Of course this discussion relies largely on conjecture (since i have have no knowledge regarding your hosting setup), so YMMV.

the utmost execution duration of the PHP-scripts could be exceeded

So just call set_time_limit(0);. That how it is for.

I discovered this link: http://jasny.internet/articles/how-i-php-x-sendfile/. X-Sendfile is really a module which appears to permit precisely what I wish to do. It redirects your body from the HTTP-response and can Apache let handle everything. I simply installed and attempted it and delay pills work fine.