title: Symfony 2 asset, check if file exists performance
body: <p>on symfony 2, using <code>Twig</code> you can use the <code>asset()</code> function to link an image in the way<br>
   <code>{{ asset('path_to_the_image') }}</code>, now if the file does not exists then the src of the file keeps the same, </p>
  
  <p>Thinking about that, I was tempted to create another Twig function on my <code>TwigExtensions</code>, in order to check the file existence, in order to do the following, If the file exists then I will use the given url and if does not exists then I will change the result of the function to a default image that I will use as a not_image image.
  The motivation for this function is to always show an image to the user.</p>
  
  <p>Now, my question.</p>
  
  <p>I can't figure out the performance issues with this approach because I will check the file twice, the first time to check if exists and the other time is the request that asks for the file. And the usual thing to do is to put the asset address and in case the file does not exists replace it with some default file using javascript.</p>
  
  <p>I will use php's file_exists function, and on the manual I have read that is very inexpensive and that in case that the file indeed exists the result is cached to avoid performance issues.</p>
  
  <p>Thanks in advance...</p>