Calling a file at every TimThumb run

3

I use TimThumb to upload and resize images. However, at the end of the project, making changes to the .htaccess for optimization (activating gzip, minify, leverage browser caching and more), something that I considered error persisted:

TimThumb is running once, on each image, note the figure below:

Would there be any method for me to do a loop in the script? Each tim.php reported in the image above is an image loaded by it, the URLs are being shown as follows:

http://meusite.com.br/tim.php?src=http://meusite.com.br/uploads/2013/11/nomedaimg&w=160&h=80&zc=1&q=100&a=t

My site is taking 5 seconds to open, this is really bothering you.

    
asked by anonymous 13.02.2014 / 09:03

2 answers

0

After knowing a bit about this image library and analyzing the question graph, I can comment on some possible causes of slowness ...

TimThumb is always processing all images

This does not seem to be the case, as several lines of the graphs show only green bars, which means that time was spent with image transfer rather than processing.

Note that it does not make much difference for the URL to be tim.php , as long as the library is just writing a cache image to the output as this is quick.

In any case, make sure that the images are being written to the directory set to cache. If they are not, adjust the script's permission for the folder.

TimThumb is sending some header which prevents caching

Use your browser's browser developer tool ( F12 ?) to monitor the network and verify that after accessing the same page a second time, images will be uploaded of the browser cache and not download again.

Your server is slow

Honestly, for some shared hosting, 5 seconds is up to a reasonable time for the level of processing your site seems to be using. I even use bluehost for my blog, and if it were not for the Wordpress cache plugins, the loading time could easily double that.

Large number of downloaded files

Another factor seen in the chart is that there are a large number of elements downloaded in the page access. This also has a negative impact, even if your network bandwidth is good, because browsers limit the number of simultaneous connections. The limit is usually between 2 and 6 connections ( see this answer from SOEN ).

However, this would be greatly mitigated in your case after the second access to the site, because at least web fonts , styles and scripts would be cached in the browser. Of course the price would be paid on the first access, but if the content is good it's worth it.

Conclusion

I'm inclined to think that there is not a specific problem with TimThumb.

I would do some testing by placing static images and also checking if the browser is able to use the cache properly and load the page more quickly from the second access.

Finally, if the question were performance, there are techniques to improve this, such as hiring a more powerful server or even more specialized cloud caching services.

    
13.02.2014 / 13:24
0

Ajax to avoid user waiting

Good morning, have you considered passing an array with the src of the images to a function that would loop the timthumb, getting the result by ajax? I think that would be interesting.

Resizing once.

Another thing. For example, wordpress generates all thumbnails once, several standard dimensions, so you do not have to redo them every time you refresh . That way, following this idea is quite valid.

You would generate various sizes (if needed) or the size you want.

  
  • Thumbnail (default 150px x 150px)
  •   
  • Medium size (default 300px x 300px)
  •   
  • Big size (default 640px x 640px)
  •   
  • Original size (without modification)
  •   

    After that, you could check the existence of the thumbnail-specific folder for each image, if you do not want to keep the history in a table in the DB.

        
    13.02.2014 / 13:08