So, I have three server, and the idea was to keep all media (images, files, movies) on a media server. I never got around to do it but I think I probably should.
So these are the three servers:
WWW server
DB server
Media server
Visitors obviously connect to the WWW server and currently image resizing and cache:ing is done on the WWW servers as the original files are kept there. So the idea for me is for image functions I have, that does all the image compositioning, resizing and cahceing would just pie the command over to the media server that would return ther path to the finnished file.
What I don’t know is how to handle functions such as file_exists() and figuring out image dimensions when needed before even any image management comes into play. Do I pipe all these commands to the other server, via HTTP? I was thinking along the ways of doing it this way:
function image(##ARGS##){
if ($GLOBALS["media_host"] != "localhost"){
list ($src, $width, height) = file('http://$GLOBALS[media_host]/imgfunc.php?args=##ARGS##');
return "<img src='$src' height and width >";
}
.... do other stuff here
}
Am I approaching this the wrong way? Is there a better way to do this?
Imagine the media server as an S3 bucket, would probably make your life easier to understand what should happen where. Install lighthttpd on the media server and serve the images directly from there. For storage, process the image on the main server, upload the image to the media server, store all the info related to the image in the database, so that when you want to serve it, you already have all the info available and you assume for all the right reasons that the image is still there 🙂
As for the way you want to do it, i think it would cause a serious bottleneck and raise alot of network traffic, you are kind of trying to implement “messages” found in distributed systems and we all know the pitfalls involved there. I say keep it simple!