doujingxi3356 2017-02-07 08:39
浏览 70

如何在PHP中有效地实现反向代理?

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:

  1. 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.

  2. 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

  3. 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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 arduino控制ps2手柄一直报错
    • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
    • ¥85 maple软件,solve求反函数,出现rootof怎么办?
    • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
    • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
    • ¥50 树莓派安卓APK系统签名
    • ¥65 汇编语言除法溢出问题
    • ¥15 Visual Studio问题
    • ¥20 求一个html代码,有偿
    • ¥100 关于使用MATLAB中copularnd函数的问题