2
votes

I'm testing my PHP script with Paypal sandbox, the script works with www.paypal.com but not www.sandbox.paypal.com. I recently received an email from PayPal asking to use HTTP 1.1 protocol instead of 1.0 so I have done that, and i'm using the Connection: close in the header as specified, but the IPN URL hangs. When I try it with www.paypal.com there is no hanging.

PayPal did specificy this in their second email

This is a follow-up to the bulletin we sent on 6 September, 2012. It has come to our attention that some merchants were experiencing issues getting their IPN scripts updated to use HTTP 1.1 because the scripts would get "hung" or take a long time to get a ‘VERIFIED’ response. We are including instructions on how to remedy this issue by adding a "Connection: close" header in the HTTP request.

But clearly that doesn't work.

$header = "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Host: $url\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$header .= "Connection: close\r\n";

Any ideas? Help much appreciated.

2

2 Answers

1
votes

You have the \r\n\r\n on the 2nd to last line, it needs to go on the last line...

$header = "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Host: $url\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n";
$header .= "Host: www.paypal.com\r\n"; 
$header .= "Connection: close\r\n\r\n";

You also need the Host line.

0
votes

I don't know the answer as to why it hangs, but using curl instead of fsockopen seemed to solve my problem. I used the solution on here;

https://www.x.com/developers/PayPal/documentation-tools/code-sample/216623