How do I pass binary data across multiple http servers?

Well, the question doesn't have to be that big. Let me explain the scenario: I have two http servers. server A is accessible to the end user by a web browser, whereas server B is an internal server that can only be accessed by server A. If server B generates some large jpeg image on the local disk and server A does not have the ability to directly access the server file system B, how to let the end user see this image without storing the data of these images on server A first?

I am running PHP on server A and perl on server B, but it doesn't matter. I need a general outline to implement this.

+2


a source to share


2 answers


obviously we can't just deliver this image path to server A and ultimately to the end user.

I think this is 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 at the filesystem level (i.e. via a network share), server A can receive data from server B and pass them 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 should change the second line to something like

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

      



if this method is too slow for you or not suitable for configuration, you will need to use (S) FTP, SCP, or something similar. FTP is available natively in PHP ; other protocols are probably easiest to call from a PHP script using exec()

.

depending on your scenario and frequency of use, you might want to use 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 the traffic between them is free or not too expensive.

This is the fastest way I can think of to let the user "see" the image without infecting it with Server A.

+3


a source


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

One way is for Server B to be able to create images on a network volume shared by Server A. Server A would have read-only access to provide a bit of security. Server A can then directly access the specified files. The advantages over writing an end-to-end program on Server A are likely to be faster, since only the additional overhead is the network drive and allows Server B to remain completely isolated from Server A.



This assumes that server A does not have to ask server B to generate images that they are there.

0


a source







All Articles