Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP CURL Error - curl: (56) Recv failure: Connection reset by peer

Tags:

php

curl

basically, this error only occurs in CURL

curl: (56) Recv failure: Connection reset by peer

But when I visit it directly the link directly on my browser, it works!

What are your recommendations on fixing this one or the cause of this error?

Note: the server is coded in ASP and it only occurs on one API Call

like image 442
Jeffrey Monte Avatar asked Jul 16 '12 08:07

Jeffrey Monte


People also ask

What is curl 56 error?

The Curl error 56 means there's an error on the hosts' side. It could be a server-side restriction or a loopback error on the server (if they say they don't allow loopbacks, then that's the culprit in your case).

What is Connection reset by peer?

Connection Reset by peer means the remote side is terminating the session. This error is generated when the OS receives notification of TCP Reset (RST) from the remote server.


2 Answers

I resolved this issue by removing whitespace characters from the URL. In my situation, it was the proxy server that was erroring out, not the web server.

In PHP:

     curl_setopt($ch, CURLOPT_URL, trim($url));
like image 153
Adam Albright Avatar answered Oct 04 '22 17:10

Adam Albright


I remember facing the same issue a long time back. While I don't remember what exactly sorted out the issue, I remember trying the following:

  1. I was trying to pass the query parameters in the URL directly and I tried passing through POST method

  2. I tried using a proxy with curl to see if I was possibly being blocked by the other server

  3. I believe I also asked my host to look into it and they made some Apache setting changes

like image 31
Sam Avatar answered Oct 04 '22 15:10

Sam