tags:

views:

55

answers:

2

Well, the question is not intended to be that big. Let me explain the scenario: I have two http servers. server A is accessible to end user by web browser, while server B is internal server which can only be accessed by server A. If server B generate some big jpeg image in local disk, and server A has no way to access server B's filesystem directly, how to let end user see those image without firstly storing those image data in server A temporarily?

I run PHP on server A and perl on server B, but this should not matter. I need a general pattern for implementing this.

+3  A: 

obviously we can't just delivery those path to image to server A and eventually to end user.

I think that's the only way to go, but you don't need to physically save the files on server A. In PHP: If server A can talk to server B on filesystem level (i.e. through a network share), server A could fetch the data from server B and pass it through to the user:

header("Content-type: image/jpeg"); // Make sure you send the right headers
$file = fopen("/path/to/server/b/huge/image.jpg", "r");
fpassthru($file);  // or deliver chunks using fread()
fclose($file);

If there is only an internal http connection, you would change the 2nd line to something like

$file = fopen("http://serverb.local/huge/image.jpg", "r");

if this method is too slow for you or not convenient to set up, you would have to use (S)FTP, SCP or something similar. FTP is available in PHP natively; the other protocols are probably easiest to simply call from the PHP script using exec().

depending on your scenario and use frequency, you may want to employ some sort of caching on Server A, so that this operation doesn't have to be repeated every time.

If your servers are hosted in a datacenter, make sure that traffic between them is free or not too expensive.

This is the leanest way I can think of to let the user "see" an image without it clogging Server A.

Pekka
This is the right solution within the given constraints. Just wanted to add that you don't need network share fopen can read the internal url.so $file = fopen('http://mySeverBIp/hugeImage.jpg') would work too.
elviejo
@elviejo: sorry, what is "myServerBlp"?
solotim
@solotim if I understand @elviejo right, it's the IP of server B. It's correct that this would work (it could even be the only way depending on the scenario) but it would use the HTTP transport protocol. I think http would be slower and more strain on server B than directly working with a network share.
Pekka
@Pekka: thank your for the explaination. I thought Blp is some kind of acroynm. :)
solotim
A: 

There's a number of solutions, depending on how much control you have and just how isolated server B is from server A.

One way is for server B to generate the images on a network volume shared with server A. Server A would have read-only access to provide a bit of security. Then server A can directly access the files in question. The advantages over writing a pass-through program on server A is its likely to be faster, as the only extra overhead is the network drive, and it allows server B to remain completely isolated from server A.

This does assume that server A does not need to request that server B generate the images, that they're just there.

Schwern
Thank you. I'v update my question, sorry, server A is not allowed to access server B's filesystem.
solotim
It wouldn't be a physical disk on server B, but a network drive visible to both A and B. In fact, it could be a shared volume on server A, assuming server A can accept connections from server B.
Schwern