开发者

Using up bandwidth when calling readfile() on a different server?

I hav开发者_StackOverflow社区e a question about how servers communicate with each other and how it takes up bandwidth. I'll use an example to better explain my question.

I have two sites: www.jojoedad.com and resources.jojoedad.com. Each site resides on a separate server (with different IPs and on different machines). "www| is used mainly for handling front-end tasks such as serving up different web pages. "resources" stores a whole bunch of video files and is meant to only serve up large video files.

Assume that I code it correctly so only "www" can be accessed by the public and "resources" can only be accessed by calling scripts on "www". Will large bandwidths of "www" be taken up if users retrieve videos on "resources" through www.jojoedad.com like this:

http://www.jojoedad.com/getVideo.php?filename=myVideo.mp4

and in getVideo.php, I have something like this:

header("Content-Type..."); // I didn't fill in details for this line
header("Content-disposition..."); // I didn't fill in details for this line
header("COntent-description..."); // I didn't fill in details for this line
readfile("http://resources.jojoedad.com/video_files/{$_GET['filename']}");

Thanks in advance!


Yes, because as the process is now, you're doing this:

  1. www connects to resources
  2. www downloads video from resources
  3. www streams video to user

Meaning you're doubling your work. The script that puts out the video files should be on resources.joedad.com and use your header calls plus readfile using the path to the video file. An example would be:

readfile('/home/user/videos/myVideo.mp4)

so it doesn't have to make a connection to itself.


The fun thing is this will use twice the bandwidth on www -- once to retrieve the file from resources and once to send the data to the client -- and once on resources. Many data centers charge less (or nothing) for internal data traffic, so it might not be a big deal.

If you like restricting access to resources to come from www and only from www, then it might even be worth the triple-bandwidth costs to get a file from resources to www and then again from www to the client.


Yes, it will use the bandwidth needed by the video once on resources and once again on www

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜