Wordpress主题导致高服务器负载

时间:2015-02-24 18:35:48

标签: php wordpress

我编辑了一个主题,导致我的服务器负载非常高,

首先,我使用此代码仅从内容中获取文本

        $response = get_the_content();
        $content = $response;
        $content = preg_replace("/(<)([img])(\w+)([^>]*>)/", "", $content);
        $content = apply_filters('the_content', $content);
        $content = str_replace(']]>', ']]&gt;', $content);

然后我想获取帖子内容中的所有图片,所以我使用了“DOMDocument”代码:

            $document = new DOMDocument();
            libxml_use_internal_errors(true);
            $document->loadHTML($response);
            libxml_clear_errors();
            $images = array();
            $imgsq = $document->getElementsByTagName('img');

我的每个帖子都包含一个静态部分而不是所有照片页面,所以我使用该代码来获取它

function findit($mytext,$starttag,$endtag)  {

              $posLeft = stripos($mytext,$starttag)+strlen($starttag);
              $posRight = stripos($mytext,$endtag,$posLeft+1);
              return substr($mytext,$posLeft,$posRight-$posLeft);

          }

            $project = @findit($content , '-projectinfostart-' , '-projectinfoend-');
            $check = str_replace('ializer-buttons clearfix">', '', $project);

              if($project != $check) $project = '';

              $replace = array('-projectinfostart-' , '-projectinfoend-' , $project ,  '<p>&nbsp;</p>');
             $content = str_replace( $replace, '', $content);

然后我最后想要以拇指大小拍摄所有照片,所以我使用了那段代码:

  foreach($imgsq as $key => $img) :
                   // Extract what we want
                      $image = array('src' => $img->getAttribute('src') );

                  if( ! $image['src'])
                     continue;

                if($key == $page) :
                     echo '<center><img style="height: auto !important;max-height:450px;" class="responsiveMe" src=" ' . $image['src'] . '" /> ';
                 endif;
                   $srcs[$key] = array();
                   $srcs[$key]['src'] =  wp_get_attachment_thumb_url(get_attachment_id_by_url($image['src']));
                   $srcs[$key]['full'] = $image['src'];

                if(!empty($project)) $description = '<p>' . $project . '</p>';
                else $description = '';

endforeach;

我的服务器是16 GB Ram,无法在单个帖子页面上与1500名在线用户一起使用!关于导致这种高负荷的原因的任何想法?

感谢。

0 个答案:

没有答案
相关问题