CURL在localhost上不在服务器上工作

时间:2015-05-15 04:13:49

标签: php curl localhost

我完全是CURL的新手。我有一个问题。

我有下面的脚本应该使用代理获取远程文件,我在我的本地主机上尝试这个代码并且它运行良好"成功完成部分:。

当我从服务器运行它时,它只是继续进入"无效代理"虽然它与本地主机中使用的代理相同..

<?php
$dots = '';
include($dots.'classes/config.php');
$wordsLimitPerCall = 1;
$maxAttemptsTrials = 3;
$timeout = 10; // Seconds


$proxy = sqlSelectRow('proxy', array(
    'condition'=>'not_valid=0',
    'order'=>'rand()'
));
echo '<ul>';
if($proxy)
    echo '<li>Using proxy: '.$proxy['proxy'].':'.$proxy['port'].'</li>';
$wordsRes = sqlSelectRows('words', array(
    'condition'=>'is_done=0 and trials<'.$maxAttemptsTrials,
    'limit'=>$wordsLimitPerCall,
    'order'=>'created asc'
));
while($arr = $wordsRes->fetch_assoc()) {

    $word = urlencode($arr['word']);

    $url = 'http://example.com'.$word;
    $callSettings  = array(
        'method'=>'curl', 
        'timeout'=>$timeout
    );
    if($proxy)
        $callSettings['proxy'] = $proxy['proxy'].':'.$proxy['port'];
    $result = callRemoteURL($url, $callSettings);
    $filename = urldecode($word);

    $filename = 'file/'.$arr['id'].' - '.$filename.'.mp3';
    echo '<li>Getting the word: '.$word.'</li>';
    if($result && strpos($result, '<html')===false) {
        if(file_exists($dots.$filename))
            unlink($dots.$filename);
        fileWrite($filename, $result);
        $is_done = 1;
        echo '<li>done successfully</li>';
    }
    else {
        $is_done = 0;
        if($proxy) {
            sqlUpdate('proxy', array(
                'not_valid'=>0
            ), array(
                'condition'=>'id='.$proxy['id']
            ));
            echo '<li>Proxy is not valid</li>';

        }
    }
    sqlUpdate('words', array(
        'trials'=>$arr['trials']+1,
        'path'=>$url,
        'last_call_date'=>date('Y-m-d H:i:s'),
        'is_done'=>$is_done
    ), array(
        'condition'=>'id='.$arr['id']
    ));

}
echo '</ul>'; ?>

在从utils

调用的函数下面
<? php 


                if($set['method']=='curl' && extension_loaded('curl'))
                        {
                            $ch = curl_init();
                            curl_setopt($ch, CURLOPT_URL, $url);
                            curl_setopt($ch, CURLOPT_HEADER, 0);
                            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
                            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
                            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,0); 
                            curl_setopt($ch, CURLOPT_TIMEOUT, $set['timeout']); // Seconds
                            if($set['proxy'])
                                curl_setopt($ch, CURLOPT_PROXY, $set['proxy']);
                            ob_start();
                            if(curl_exec($ch) === false)
                            {
                                $errorNo = curl_errno($ch);
                                if($errorNo==28)
                                    print_r('The connection took time more than '. $set['timeout'].' seconds, so we disconnected the process');
                                else
                                if($errorNo!=7)
                                    print_r(curl_error($ch));
                                $result=false;
                            }
                            else
                            {
                                $result = ob_get_contents();
                            }
                            ob_end_clean();
                            return $result;
                        }
        ?>
抱歉,如果它太长了......但是我花了几天时间试着找出来。任何想法或我该怎么做?

0 个答案:

没有答案