I was recently had an nginx + php-fpm server that was serving images like so:
header('Content-Type: image/png');
echo file_get_contents('example_image.png');
exit();
What I am came to realize, whether the image was cached or not, there was a huge peformance hit on the server. CPU utilization was extremely high, 100% with a minimal amount of connections. So I started to offload the images to a CDN and there was an immediate performance improvement but in some cases I still do require the image to be served through a server, which has brought me to the idea of image/media server.
My question is, is there a specific type of server that I should be using? One that can communicate with a database to find the images location and serve it? File system type? Or am I better off keeping just firing up another nginx + php-fpm instance and create a cdn like structure implementation where:
media.example.com
points only to that server, thus there is no performance impact on the web server?