Joomla site on LAMP server behind proxy cannot access HTTP resource stream

Setup: 1. Joomla 1.5 website on LAMP server (CentOS 5.2 / Apache 2.2 / PHP 5.2.9 / mysql 5) 2. Added Joomla module for currency conversion. The module uses Google for currency conversion 3. The LAMP stack is on the intranet behind a proxy server. The server environment variables for http_proxy, yum.conf proxy have been configured, and the kernel has been successfully updated. 4. phpinfo () clearly shows curl is installed 5. the module mentioned in "2." allows 3 ways to connect to google finance, fread (), file_get_contents () and using cURL libraries. Since the field is behind a proxy, only the cURL libraries method should work.

Problem: On the WAMP stack, the curl library method works fine. However, on the lamp stack, the module is unable to communicate with google finances and throws a connection timed out error message. Here's some code to make it clearer.

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);
            }
    }

      

I even tried adding curl_setopt ($ ch, CURLOPT_PROXY, '10 .x.xx.xx: 8080 '); after curl_init (), to no avail. I have compiled apache with libcurl and php and I need to know the following: 1. How can I instruct php to route outgoing requests (streams) through a proxy server? 2. Do I need to configure cURL (libcurl) with proxy and port? 3. I have disabled iptables so the linux firewall is no longer in the image, is there anything else I need to do to allow outgoing requests? 4. I set up a proxy so that my LAMP stack is unlocked for all content, cURL works from the command line, but not php / apache. What am I missing? Any environment variables? Any switches?

Thanks in advance for your time.

Srinivas

+1


source to share


1 answer


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 probably want to use curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);

and curl_setopt($ch, CURLOPT_PROXYPORT, 8080);

.

+1


source







All Articles