Windows 7上的php curl无效:返回false

时间:2017-10-04 07:09:20

标签: php curl

我有一个运行Win7和Apache 2.4以及PHP 7的系统。

即使激活curl ext(只有这个扩展名)也有点困难,但顺便说一句(现在,phpinfo说它现在正在工作),我想用它,但尝试了很多脚本,从旧新的但没有工作,最后在var_dump($ result)我每次都得到boolean(false);

function curl_download($Url){

    // is cURL installed yet?
    if (!function_exists('curl_init')){
    die('Sorry cURL is not installed!');
    }

    // OK cool - then let's create a new cURL resource handle
    $ch = curl_init();

    // Now set some options (most are optional)

    // Set URL to download
    curl_setopt($ch, CURLOPT_URL, $Url);

    // Set a referer
    curl_setopt($ch, CURLOPT_REFERER, "http://www.example.org/yay.htm");

    // User agent
    curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");

    // Include header in result? (0 = yes, 1 = no)
    curl_setopt($ch, CURLOPT_HEADER, 0);

    // Should cURL return or print out the data? (true = return, false =     print)
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    // Timeout in seconds
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);

    // Download the given URL, and return output
    $output = curl_exec($ch);

    // Close the cURL resource, and free system resources
    curl_close($ch);

    return $output;
}

我已经尝试了许多经过检查的脚本,这应该可行,但我认为,原因是,curl无法连接到网站(我已经测试了很多)。是否有任何可能破坏连接过程的防火墙或代理?

提前致谢和欢呼!

1 个答案:

答案 0 :(得分:0)

我找到了解决方案。如果您使用代理服务器,那么curl无法与公共网络建立连接:(因此您必须连接到公共网络的另一种方式。这就是全部。