关于PHP的cURL好奇地保持沉默

OK so after struggling for a while trying to get cURL to fetch a password protected XML file, and getting absolutely nothing from it, I tried dumbing down my code to see what would work. It turns out nothing. Here's my code:

$ch = curl_init("www.google.com");

curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

curl_exec($ch);

curl_close($ch);

And cURL is SILENT. I mean nothing prints to the page. I definitely have it enabled, my phpinfo looks like this:

cURL support            enabled
cURL Information            libcurl/7.16.0 OpenSSL/0.9.8a zlib/1.2.3

Running php 5.2 on a Windows NT server. Any suggestions?

The key is in this line:

curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

You're telling cURL to return the result of the transfer instead of echoing it (the default). So either remove that line, or do something like this:

$result = curl_exec($ch);

if ($result === false) {
    echo "Error: " . curl_error($ch);
} else {
    echo $result;
}

If you're getting an SSL error as you point out in your comments, you can set another option on the cURL handle to disable checking the certificate:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);