tags:

views:

46

answers:

2

Hi

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 clearer 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

A: 

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.

Matijs
In the past I have set the timeout to 0 (as well as set_time_limit(0)) but the error persists. But I assumed if it was a timeout error, it should be throwing that after the time limit is exceeded. I am seeing no errors in the log.
dontaskagain
A: 

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));
}
Marc B
The script will not process past curl_exec. I have tried something similar to what you suggested, but unfortunately i never get to see it's output.
dontaskagain