I generate dynamically graphic in my controller:
if not file exists (unique filename) then generate graphic and save it
return RedirectResponse($url)
(3. I've tried also:
$fp = fopen($url, "rb");
$str = stream_get_contents($fp);
fclose($fp);
$response = new Response($str, 200);
$response->headers->set('Content-Type', 'image/png');
return $response;
)
I need it to generate dynamically userbars for users [on this graphic some text will be automatically updating if some changes will be done on my websites].
So it's important for me that this script works fast and doesn't kill my server/bandwitch. To achieve that I've made cache where all generated graphics are stored. But i've got a problem with speed, solutions which i've described above are pretty slow, when i've tested it in chrome with developer tool (F12) then it shows me that both solution (2. and 3.) takes about ~1s (when the same graphics [without controllers etc. just direct url to .png] loads 44ms).
So if only for me it takes about ~1s per graphic then if for example 1000 users will generate at the same time this graphic it can slower my website I think.
Please help, do you know any faster ways to do that?
PS. Redirect isn't most desire thing for me, because I would prefer to leave url as it is, for example smth/username/userbar/ insted of smth/img/userbars/cache/blabla.png. But if it will be much faster then I can stand it :).
EDIT: To be clear: I'm not looking for solution to cache images, my problem is that returning images via controller (already generated images, just from ftp) takes about 1s, when normally if you do for example
<img src="direct_url_to_png">
it takes about 44ms.