2013-12-01 15:26 阅读 69


My previous posts have hard-coded HTML code to use timthumb.php to display images.

I learnt I shouldn't use timthumb.php because it slows down web server a lot, so I added following code in the beginning of timthumb.php

$pic = $_GET['src'];
header("location: ".$pic);

However, from my observation in htop, my web server (a VPS) load is still very heavy. My site is based on Wordpress with 20k-30k PV per day. Usually my web server could take much heavier load, but now it seems not. The only difference I could think of is timhumb.php.

Does it make that much difference? Any suggestions?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    dousu1916 dousu1916 2013-12-01 17:00

    First of all - check which timthumb version you have , and if it is a problematic one , go ahead and update it .

    Second - yes, timthumb and other methods CAN , depending on server and script settings, slow down the site . My suggestion for you is getting rid of it just to test server loads and decide after testing .

    My way for doing that ( and I have done it on many sites ) was to change all instances of (example)

    $img =  wp_get_attachment_image_src( $image_id , 'full' );
            if( !empty($img) ){
                return $img_src = get_template_directory_uri()."/timthumb.php?src=". $img[0] ."&h=".$height ."&w=". $width ."&a=c";


    $image_url = wp_get_attachment_image_src($image_id, array($width,$height) );  
            return $image_url[0];

    or , depending on your context

    $image_id = get_post_thumbnail_id($post->ID);  
            $image_url = wp_get_attachment_image_src($image_id, array($width,$height) );  
            return $image_url[0];

    While of course using add_image_size() with the wanted sizes and crop methods, and then use the regenerate thumbs plugin .

    点赞 评论 复制链接分享