I want to reverse proxy a file download in PHP.
Example: http://my-server-1/download.php?url=http://my-server-2/file.bin
The PHP script on server 1 fetches the file from server 2 and delivers it to the user.
It is a little more complicated because the request data such as URL, Cookies, Referer etc is passed in an encrypted blog that the PHP script decrypts and uses for the outgoing request.
I am aware that there are "better" solutions for this, such as nginx reverse proxying, that also offer the flexibility I want. But unfortunately they are not really suitable in this case. I would prefer to implement it in PHP.
I know that this is trivial to implement, but I am concerned about the efficiency and load on the server.
There will be many simultaneous downloads and a log of bandwidth will be used. The files delivered will usually be big media files such as Videos etc.
I considered the following options:
Build my own socket server in PHP and do not use a webserver software at all. This would probably be the most efficient since data does not need to be sent over a FastCGI socket or something like that.
Run the PHP script via FastCGI and NGINX. I would probably need a huge pool of workers, because the requests take a long time to complete. This is not really the scenario FastCGI usually seems to be used in, but I don't know whether there are any inherent problems
Use Apache2 with the built in mod_php module. This would elimiate the need for passing the data through the FastCGI interface.
I have bad experiences with Apache2 in high-load environments in general, but in the specific situation I am inclined to believe that Apache2 would actually be the best choice, apart from implementing the socket server in PHP which I want to avoid if possible.
Which solution would be the best and why? Is there another way?
Also: What other things have to be considered? Output buffering, etc.
It also seems that the perfect choice for this would be node.js with the socket.io library. But due to my lack of experience with node.js I would like to find another way.