开发者

Debugging curl_exec

I have been having a very difficult time recently debugging a curl function within our paypal ipn module.

Here's the module we are using: http://www.oscommerce.com/community/contributions,2679 But the relevant code is below.

I am experiencing this error for about 5% of our transactions. It causes orders not to be updated to a paid status.

I have determined that it's curl_exec which is failing and stopping further scripts being processed. There are no errors related to this in the error log on cpanel.

I have tried altering both the curl and php time out durations with no change. I have tried using try and catch but that didn't help either.

As the scripts stop being executed when it hits curl_exec i can't use curl_error to get any feedback about the problem.

I have looked through the parameters which are being passed to the IPN but they are fine.

I feel like I have tried all I can to determine the cause of this problem and got no where.

I experience the same problem if the script uses fsock as it's primary method of connecting.

If anyone has any suggestions on other methods of debugging this problem i'd appreciate it.

Thanks

if (MODULE_PAYMENT_PAYPAL_IPN_GATEWAY_SERVER == 开发者_如何学C'Live') {
 $server = 'www.paypal.com';
} else {
 $server = 'www.sandbox.paypal.com';
}

$fsocket = false;
$curl = false;
$result = false;

if (function_exists('curl_exec')) {
 $curl = true;
} elseif ((PHP_VERSION >= 4.3) && ($fp = @fsockopen('ssl://' . $server, 443, $errno, $errstr, 30)) ) {
 $fsocket = true;
} elseif ($fp = @fsockopen($server, 80, $errno, $errstr, 30)) {
 $fsocket = true;
}

if ($fsocket == true) {
 $header = 'POST /cgi-bin/webscr HTTP/1.0' . "\r\n" .
              'Host: ' . $server . "\r\n" .
              'Content-Type: application/x-www-form-urlencoded' . "\r\n" .
              'Content-Length: ' . strlen($parameters) . "\r\n" .
              'Connection: close' . "\r\n\r\n";

 @fputs($fp, $header . $parameters);

 $string = '';
 while (!@feof($fp)) {
  $res = @fgets($fp, 1024);
  $string .= $res;

  if ( ($res == 'VERIFIED') || ($res == 'INVALID') ) {
   $result = $res;

   break;
  }
 }

 @fclose($fp);



} elseif ($curl == true) {
 $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_close($ch);
}


if you use "@" php will not display the error any more, it will suppress the error. So i recommend to remove this, and then start debugging.


I know this doesn't answer your question of how to get curl_exec working, but do you have a good reason to not just use fsock? I've been running my IPN listener on fsock only and it works like a charm...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜