Can't track down bug
The following is part of a script which is used to authenticate paypal payments.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://' . $server . '/cgi-bin/webscr');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
curl_error($ch);
curl_close($ch);
On some rare occasions there is a problem with curl_exec which causes the the script to stop executing at that line.
No errors are recorded in the cpanel error log and after trying a number of different things I am no c开发者_高级运维learer as to what may be causing this error with curl.
I am not very familiar with curl, so if anyone knows of a good way to obtain error information from this, or what could possibly cause this problem, I'd really appreciate it.
Thanks
It could just take a long time.
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
Set the time out to 30 seconds. Are you sure you waited that long?
Use CURLOPT_TIMEOUT_MS
to set the timeout in milliseconds.
curl_error()
returns a string, it doesn't do any output/logging of its own. The proper way to detect curl errors is as follows:
$result = curl_exec($curl);
if ($result === FALSE) {
error_log("CURL failed at " . date('c'));
error_log("CURL message: " . curl_error($curl));
}
精彩评论