duanpo6079 2013-12-01 15:26
浏览 76
已采纳

如何忽略timthumb.php?

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);
die();

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 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";
            }
    

    with

    $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 .

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入