全球主机交流论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

CeraNetworks网络延迟测速工具IP归属甄别会员请立即修改密码
查看: 3228|回复: 11

[已解决] cpu100%求助技术高手

[复制链接]
发表于 2012-5-8 17:14:01 | 显示全部楼层 |阅读模式
目前已经确认是这个原因:插件用了这个PHP 的 file_get_contents()
因为我用了一个dx2自动保存图片的插件
网上查到说可以换成这样<?php
$ctx = stream_context_create(array(
   'http' => array(
       'timeout' => 1 //设置一个超时时间,单位为秒
       )
   )
);
file_get_contents("http://hostloc.com/", 0, $ctx);
?>

但我不知道怎么换,有高手指点一下吗,试了几次都不行;要是有好用的dx2自动保存图片的插件共享下也行
插件源码如下
<?php
if(!defined('IN_DISCUZ')) {
        exit('Access Denied');
}

class

plugin_yxf_picdown {

}

class plugin_yxf_picdown_forum extends

plugin_yxf_picdown  {
        function post_picdown(){
               

global $_G;
                @extract($_G['cache']['plugin']

['yxf_picdown']);
                if(!$_POST) return '';
                if(!in_array

($_G['groupid'],(array)unserialize($usegids))) return '';
                if

(!in_array($_G['fid'],(array)unserialize($usefids))) return '';
                if

(preg_match_all("/\[img[^\]]*\](.*)\[\/img\]/isU",$_G['gp_message'],$regs)){
               

        @set_time_limit(0);
                        require_once libfile

('class/image');
                        $image = new image;
               

        if($downway==3){
                                require_once

libfile('class/ftp');
                                $ftp = new discuz_ftp();
       

                        if(!($_G['setting']['ftp']['connid'] = $ftp-

>connect())) {
                                        return

FALSE;
                                }
                        }
       

                $watermarkstatus=unserialize($_G['setting']

['watermarkstatus']);
                       
                       

$expdomains=explode("\n",str_replace("\r","",$expdomains));
                       

$expdomains[]=$_G['siteurl'];
                        foreach ($regs[1] as

$key=>$url){
                                $url=trim($url);
               

                if(substr($url,0,7)!='http://') continue;
                       

        $isexp=0;
                                foreach ($expdomains

as $domain){
                                       

$domain=trim($domain);
                                        if

($domain&&strpos($url,$domain)!==false){
                               

                $isexp=1;
                                               

break;
                                        }
                       

        }
                                if($isexp){
                       

                continue;
                                }

               

                $ym=date('Ym');
                               

$d=date('d');
                                $his=date('His');

               

                if($downway==1){//保存为文件
                               

        $dir="data/downpic/";
                                       

if(!is_dir($dir)) @mkdir($dir);
                                       

$dir.="{$ym}/";
                                        if(!is_dir

($dir)) @mkdir($dir);
                                        $dir.="{$d}/";
       

                                if(!is_dir($dir)) @mkdir($dir);
               

                        $target=$dir.md5($url).".jpg";
                       

                $attachsave=savefile($url,$target);

                       

                if($attachsave){
                                       

        if($watermarkstatus['forum'] && empty($_G['forum']

['disablewatermark'])) {
                                               

        $image->Watermark($target);
                                       

        }
                                               

$_G['gp_message']=str_replace($url,$_G['siteurl'].$target,$_G

['gp_message']);
                                        }
               

                }
                                elseif

($downway==2||$downway==3){//保存为附件
                               

        $remote=0;
                                        if

(!is_dir($_G['setting']['attachdir']."/forum/".$ym."/")) @mkdir($_G['setting']

['attachdir']."/forum/".$ym."/");
                                        if

(!is_dir($_G['setting']['attachdir']."/forum/".$ym."/".$d."/")) @mkdir($_G

['setting']['attachdir']."/forum/".$ym."/".$d."/");
                               

        $attachmenturl=$ym."/".$d."/".$his.strtolower(random(16)).".jpg";
       

                                $target=$_G['setting']

['attachdir']."/forum/".$attachmenturl;
                                       

if($downway==3){
                                               

$attachmenturl=$ym."/".$d."/".$his.strtolower(random(16)).".jpg";
               

                                $target=$_G['setting']['ftp']

['attachurl'].'/forum/'.$attachmenturl;
                                       

       
                                               

$ftp->upload($url,'forum/'.$attachmenturl);
                                       

        $remote=1;
                                               

$sizeinfo=@getimagesize($url);
                                       

        $attachsave=$sizeinfo[0];
                                       

}else{
                                               

$attachsave=savefile($url,$target);
                                       

}
                                        if($attachsave){
               

                                $width=$attachsave;
                       

                        $filename=$key.'.jpg';
                       

                        $filetype='application/octet-stream';
               

                                $filesize=filesize($target);
               

                                $isimage=1;
                       

                        $thumb=0;
                               

               
                                               

if(!$remote){
                                                       

$thumb = $image->Thumb($target, '', $_G['setting']['thumbwidth'], $_G

['setting']['thumbheight'], $_G['setting']['thumbstatus'], $_G['setting']

['thumbsource']) ? 1 : 0;
                                               

        if(!$_G['setting']['thumbsource']) {
                               

                                $width = $image->imginfo['width'];
       

                                                }
               

                                        /*
                       

                                if($watermarkstatus['forum'] &&

empty($_G['forum']['disablewatermark'])) {
                                       

                        $image->Watermark($target);
                       

                                }
                               

                        */
                                       

        }
                                               
       

                                        /*
                       

                        DB::query("INSERT INTO ".DB::table

("forum_attachment_unused")." ( `aid` , `width` , `dateline` , `filename` ,

`filetype` , `filesize` , `attachment` , `downloads` , `isimage` , `uid` , `thumb` ,

`remote` )
VALUES (NULL , '0', '0', '$width', '{$_G['timestamp']}', '0', '0',

'{$filename}', '{$filetype}', '{$filesize}', '{$attachmenturl}', '0', '{$isimage}',

'{$_G['uid']}', '{$thumb}', '{$remote}');");
                                       

        */
                                               

DB::query("INSERT INTO  ".DB::table("forum_attachment")."
                       

                        (  `aid` ,  `tid` ,  `pid` ,  `uid` ,  `tableid` ,  

`downloads` )
                                               

VALUES
                                                (NULL ,  '0',  

'0',  '{$_G['uid']}',  '127',  '0');");
                                               

$aid=DB::insert_id();
                                               

DB::query("INSERT INTO  ".DB::table("forum_attachment_unused")."
               

                                (  `aid` ,  `uid` ,  `dateline` ,  

`filename` ,  `filesize` , `attachment` ,  `remote` ,  `isimage` ,  `width` ,  

`thumb` )
                                                VALUES
               

                                ('$aid',  '{$_G['uid']}',  '{$_G

['timestamp']}',  '{$filename}','{$filesize}',  '{$attachmenturl}',   '{$remote}',  

'{$isimage}',  '{$width}',  '{$thumb}');");
                                       

       
                                               

$_G['gp_attachnew'][$aid]=array();
                                       

        $_G['gp_message']=str_replace_once($regs[0]

[$key],"[attachimg]{$aid}[/attachimg]",$_G['gp_message']);//因为当前DX不支

持多次引用附件
                                               
       

                                }
                               

}
                        }
                        if

($downway==3){
                                $ftp->ftp_close();
               

        }
                }
                //die();
        }
}


function

xdfopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ip = '',

$timeout = 15, $block = TRUE) {
        $return = '';
        $matches =

parse_url($url);
        $host = $matches['host'];
        $path = $matches

['path'] ? $matches['path'].(isset($matches['query']) && $matches['query'] ?

'?'.$matches['query'] : '') : '/';
        $port = !empty($matches['port']) ? $matches

['port'] : 80;

        if($post) {
                $out = "POST $path HTTP/1.0

\r\n";
                $out .= "Accept: */*\r\n";
                $out .=

"Accept-Language: zh-cn\r\n";
                $out .= "Content-Type:

application/x-www-form-urlencoded\r\n";
                $out .= "User-Agent:

$_SERVER[HTTP_USER_AGENT]\r\n";
                $out .= "Host:

$host\r\n";
                $out .= 'Content-Length: '.strlen($post)."\r\n";
               

$out .= "Connection: Close\r\n";
                $out .= "Cache-Control: no-

cache\r\n";
                $out .= "Cookie: $cookie\r\n\r\n";
               

$out .= $post;
        } else {
                $out = "GET $path HTTP/1.0\r\n";
       

        $out .= "Accept: */*\r\n";
                $out .= "Accept-

Language: zh-cn\r\n";
                $out .= "User-Agent: $_SERVER

[HTTP_USER_AGENT]\r\n";
                $out .= "Host: $host\r\n";
               

$out .= "Connection: Close\r\n";
                $out .= "Cookie: $cookie\r\n\r\n";
       

}
        $fp = @fsockopen(($ip ? $ip : $host), $port, $errno, $errstr,

$timeout);
        if(!$fp) {
                return '';
        } else {
               

stream_set_blocking($fp, $block);
                stream_set_timeout

($fp, $timeout);
                @fwrite($fp, $out);
                $status =

stream_get_meta_data($fp);
                if(!$status['timed_out']) {
               

        while (!feof($fp)) {
                                if(($header =

@fgets($fp)) && ($header == "\r\n" ||  $header == "\n")) {
                       

                break;
                                }
               

        }

                        $stop = false;
                       

while(!feof($fp) && !$stop) {
                                $data =

fread($fp, ($limit == 0 || $limit > 8192 ? 8192 : $limit));
                       

        $return .= $data;
                                if($limit) {
               

                        $limit -= strlen($data);
                       

                $stop = $limit <= 0;
                                }
       

                }
                }
                @fclose

($fp);
                return $return;
        }
}

function savefile($src,$target){
       

if(file_exists($target)){
               
        }
        elseif

(@copy($src,$target)){

        }elseif ($content=@file_get_contents($src)){
       

        $fp=@fopen($target,"w");
                @fwrite($fp,$content);
       

        @fclose($fp);
        }elseif ($content=@xdfopen($src)){
               

$fp=@fopen($target,"w");
                @fwrite($fp,$content);
               

@fclose($fp);
        }
       
        $sizeinfo=@getimagesize

($target);
        if(!$sizeinfo[0]||!$sizeinfo[2]){
                @unlink($target);
               

return false;
        }else{
                return $sizeinfo[0];
        }
       

return false;
}

function str_replace_once($needle, $replace, $haystack) {
       

$pos = strpos($haystack, $needle);
        if ($pos === false) {
               

return $haystack;
        }
        return substr_replace($haystack, $replace,

$pos, strlen($needle));
}

?>
发表于 2012-5-8 17:14:53 | 显示全部楼层
关机吧,骚年
发表于 2012-5-8 17:15:17 | 显示全部楼层
本机采了在发啊
发表于 2012-5-8 17:17:44 | 显示全部楼层
不懂 很深奥~
发表于 2012-5-8 17:19:56 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
发表于 2012-5-8 17:26:34 | 显示全部楼层
我遭遇死循环的时候  都是根据cpu判断重启系统的。。
发表于 2012-5-8 17:55:29 | 显示全部楼层
代码敢不敢用[code] [/code]括起来
发表于 2012-5-8 18:00:03 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
发表于 2012-5-8 18:00:10 | 显示全部楼层
小白表示什么都没看懂
发表于 2012-5-8 19:53:05 来自手机 | 显示全部楼层
小白,只能顶
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|全球主机交流论坛

GMT+8, 2024-4-30 13:21 , Processed in 0.085690 second(s), 11 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表