1

设置: 1. LAMP 服务器上的 Joomla 1.5 网站 (CentOS 5.2/Apache 2.2/PHP 5.2.9/mysql 5) 2. 添加了用于货币转换的 Joomla 模块。模块使用谷歌金融转换货币 3. LAMP 堆栈驻留在代理后面的内网中。http_proxy、yum.conf 代理的服务器环境变量已经设置好,内核更新成功。4. phpinfo() 清楚地显示 curl 已安装 5. '2.' 中提到的模块 允许 3 种方法连接到谷歌金融、fread()、file_get_contents() 和使用 cURL 库。由于该框位于代理后面,因此只有 cURL 库方法应该有效。

问题:在 WAMP 堆栈上,curl 库方法工作正常。然而,在灯栈上,该模块无法与谷歌金融通信,并抛出错误提示连接超时。这里有一些代码让它更清楚。

if (isset($_GET['process'])) {        
$url = "http://finance.google.com/finance/converter?a={
$_GET['a']}&from={$_GET['from']}&to={$_GET['to']}";
$app->get_page($url);
$data = $app->process();
}  

function get_page($url) {
if ($url!='') {
echo $url;
$ch = curl_init ();
                    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                    curl_setopt($ch, CURLOPT_URL, $url);
                    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
                    curl_setopt($ch, CURLOPT_BINARYTRANSFER, $this->binary);
                    $this->html = curl_exec($ch);
                    curl_close($ch);
            }
    }

我什至尝试添加 curl_setopt($ch, CURLOPT_PROXY,'10.x.xx.xx:8080'); 在 curl_init() 之后,无济于事。我已经编译了启用了 libcurl 和 php 的 apache,我需要了解以下内容: 1. 如何指示 php 通过代理路由传出请求(流)?2. 我需要用代理名称和端口配置 cURL (libcurl) 吗?3. 我已经关闭了 iptables,所以 linux 防火墙不再出现在图片中,我还需要做些什么来允许传出请求吗?4. 我已经设置了代理,以便我的 LAMP 堆栈对于所有内容都是畅通的,cURL 可以在命令行下工作,但不能来自 php/apache。我错过了什么?有环境变量吗?有开关吗?

在此先感谢您的时间。

什里尼瓦斯

4

1 回答 1

1

Here's an example using a local SOCKS5 proxy on port 1090:

<?php
$url = 'www.whatismyip.com/automation/<your unique whatismyip hash>';

function get_page($url, $proxy=true) {
    if ($url!='') {
        $ch = curl_init ();
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        if ($proxy) {
            curl_setopt($ch, CURLOPT_PROXY, 'localhost');
            curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
            curl_setopt($ch, CURLOPT_PROXYPORT, 1090);
        }
        $html = curl_exec($ch);
        curl_close($ch);
        return $html;
    }
}


var_dump(get_page($url));
var_dump(get_page($url, false));

You'd probably want to use curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); and curl_setopt($ch, CURLOPT_PROXYPORT, 8080); instead.

于 2009-09-25T14:42:10.130 回答