views:

149

answers:

1

Hi, I was finishing my script and suddenly libcurl stopped working. I thought the server I was connecting to was down or something, but invariably of where I try to connect I get the same sucky error. I even tried rebooting my box, same results. The code snippet where things happen is:

   public function navigate(array $data)
    {
        $ch = curl_init();

        // Setup cURL
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_INTERFACE, $data['ip']);
        curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/cookies.jar");
        curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/cookies.jar");
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_USERAGENT, $data['agent']);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

        // Visit homepage
        curl_setopt($ch, CURLOPT_URL, "SOMEWEBSITEHERE, MAKES NO DIFFERENCE");
$page=        curl_exec($ch);
var_dump($page, curl_error($ch), curl_errno($ch));
    }

The above var_dump() will produce this output (with www.yahoo.com as the URL):

bool(false)
string(51) "Failed to connect to 69.147.76.15: Unknown error 22"
int(7)
Login failed!

I even tried sniffing the connection with wireshark, cURL doesn't even issue a connection request; only a DNS request.

I'm clueless right now.

I would really appreciate a hand with this.

Thanks.

+1  A: 

Here's my complete (working) code (essentially yours, but with more output), in hopes it will help:

$url = 'www.yahoo.com';
$data['ip'] = $_SERVER['SERVER_ADDR'];
$cookie_jar = sys_get_temp_dir() . 'cookiejar.txt';
$data['agent'] = 'Mozilla/5.0 (X11; U; Linux i686; pl-PL; rv:1.9.0.2) Gecko/20121223 Ubuntu/9.25 (jaunty) Firefox/3.8';

$fp = fopen('php://temp', 'r+');
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_INTERFACE, $data['ip']);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_jar);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_jar);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT, $data['agent']);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_STDERR, $fp);
$page   = curl_exec($ch);
$errno  = curl_errno($ch);
$errmsg = curl_error($ch);
$info   = curl_getinfo($ch);
curl_close($ch);
rewind($fp);
$verbose = fread($fp, 8192);
fclose($fp);

echo '<pre>';
echo 'Error number: ' . $errno . '<br />';
echo 'Error message: ' . $errmsg . '<br />';
echo '------------------' . '<br />';
print_r($info);
echo '------------------' . '<br />';
echo $verbose . '<br />';
echo '------------------' . '<br />';
echo htmlspecialchars($page);
echo '</pre>';
GZipp