我PHP写了一个功能,是要批量下载远程文件到本地服务器,由于远程文件都比较大,所以这个程序必定会运行很久。  我的空间是 GOdaddy  的! 现在这个程序写出来了, 在GOdaddy服务器上一运行这个页面 的时候,就出错。
Internal Server ErrorThe server encountered an internal error or misconfiguration and was unable to complete your request.Please contact the server administrator and inform them of the time the error occurred, and anything you might have done that may have caused the error.More information about this error may be available in the server error log.Apache Server at okmike.com Port 80我觉得程序应该是没有错的,我在本地试的时候是可以附上我的代码
header("Content-type: text/html; charset=utf-8"); 
error_reporting(E_ALL);
set_time_limit(0);
require_once('nsp/include/NSPClient.class.php');
require_once('nsp/config.php');$clientIp = getonlineip();
//$appid $appsecret 为你申请的直链appid和secret
$appid = $APPID;
$appsecret = $APPSECRET;
$nsp = new NSPClient($appid, $appsecret);$db1 = mysql_connect('*****','****','****') or die ('nono ');  //这里的账号密码隐藏
mysql_select_db("bbs_listeneer_com",$db1) or die ("xuanze shi bai ");
mysql_query("SET NAMES 'UTF8'",$db1);$booklist =unserialize(file_get_contents('booklist.php'));
$downurl =unserialize(file_get_contents('downurl.php'));foreach ($booklist as $k=>$v){
foreach ($v  as $kk=>$vv){
$url = $downurl[$kk]['DownUrl'];
if(substr($url,0,4)!='http'){
down($url,$kk,$nsp,$clientIp,$db1);
exit;
}

}
}
function down($path,$tid,$nsp,$clientIp,$db1){
$okmikeUrl = 'http://okmike.com/db/'.$path;
//$okmikeUrl = $path;
$arr = explode('/',$path);
//print_r($arr);
$dir = dirname(dirname(__FILE__)).'/db';
if(!is_dir($dir)){
mkdir($dir);
}
$len = count($arr);
for($i=0;$i<($len-1);$i++){
$dir = $dir.'/'.$arr[$i];
if(!is_dir($dir)){
mkdir($dir);
}
}
$file = $dir.'/'.$arr[$len-1];
//exit;
$path = '/PublicFiles/'.$path;

//访问直链的service服务
$link = $nsp->service('nsp.vfs.link');
$ret = $link->getDirectUrl($path,$clientIp);
if(isset($ret["retcode"]) && $ret["retcode"] == "0000") {

//$ret['url'];exit;
if(httpdown($ret['url'],$file)){
mysql_query("insert into ytbbs_forum_book (tid,`DownUrl`) values ($tid,$okmikeUrl) on duplicate key update `DownUrl`=values(`DownUrl`)",$db1);
}
//exit;
//跳转到直链的下载地址

}function getonlineip($format=0) {
    global $_SGLOBAL;
    if(empty($_SGLOBAL['onlineip'])) {
        if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {
            $onlineip = getenv('HTTP_CLIENT_IP');
        } elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {
            $onlineip = getenv('HTTP_X_FORWARDED_FOR');
        } elseif(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {
            $onlineip = getenv('REMOTE_ADDR');
        } elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {
            $onlineip = $_SERVER['REMOTE_ADDR'];
        }
        preg_match("/[\d\.]{7,15}/", $onlineip, $onlineipmatches);
        $_SGLOBAL['onlineip'] = $onlineipmatches[0] ? $onlineipmatches[0] : 'unknown';
    }
    if($format) {
        $ips = explode('.', $_SGLOBAL['onlineip']);
        for($i=0;$i<3;$i++) {
            $ips[$i] = intval($ips[$i]);
        }
        return sprintf('%03d%03d%03d', $ips[0], $ips[1], $ips[2]);
    } else {
        return $_SGLOBAL['onlineip'];
    }
}function httpdown($url,$newfname){
set_time_limit(0);
        
$file = fopen ($url, "rb");         
if ($file) {         
$newf = fopen ($newfname, "wb");         
if ($newf)         
while(!feof($file)) {         
fwrite($newf, fread($file,1024*8),1024*8);         
}         
}         
if ($file){         
fclose($file);         
}         
if ($newf){
fclose($newf);         
}  
if($file && $newf){
return true;
}
return false;
}是不是godady 服务器上面做了很多限制,如何绕开这些限制

解决方案 »

  1.   

    你用ini_set修改一下php.ini的配置
      

  2.   

    可能是间运行太长了, 你在最开头加句:
    set_time_limit(0); //无限运行
      

  3.   

    http://www.cnblogs.com/songxiii/archive/2011/03/15/1985139.html
    這篇文章你看下,寫的很詳細
      

  4.   

    php错误提示没打开?查看apache错误日志看看有不有错误信息。
      

  5.   

    虽然你有 set_time_limit(0);
    但这只能约定 php 不超时
    你需要注意的是:web 服务器也有个超时问题。他不会在启动一个 php 进程后就无限制的等待下去
    你可以在程序运行中不时的输出点什么,以防止web服务器误以为你的php崩溃了