Ways To Fix cURL 56 recv Failure Connection Reset By Peer In CentOS

Multiple users have been experiencing the cURL 56 recv failure connection reset by peer in CentOS. When network data is not successfully received, this error is caused. It typically occurs when a URL is used incorrectly or when a lengthy procedure is happening on the server and leaving it idle. 

Here, we will try to understand the causes of this error and the possible fixes to resolve the error permanently.

cURL 56

What are the causes of the error and How do we fix it?

The cURL 56 recv failure connection reset by peer can be caused by restrictions in the firewall, server connection that has been idle, whitespace character between the URL, et cetera. These errors are temporary in nature and they can be fixed easily. Let us look at the solutions for this kind of error.

Server Connection is Idle 

Many users get the cURL 35 TCP connection reset by peer error when they are transferring the backup to a remote location.

Solution

In such cases, it is necessary that we first check the log for the backup files and see if the backup was successful or not. The server would have been idle when the backups to Google drive happened. To prevent such scenarios:

  1. Use the latest versions of cURL as well as PHP.
  2. The system firewall should not block the user connection.
  3. Upgrading the operating system can prevent TCP/IP problems.
  4. Default value of 1500 bytes should be the value of the Maximum Transmission Unit (MTU).

Repository is Bad 

An Out of date or a corrupted repository URL can be a probable cause of this error. It is common to receive the below-mentioned error when someone is installing PHP on a CentOS7 server.

Loaded plugins: fastestmirror, langpacks

http://mirror.xxx.net/el7-x86_64/rpms/ … repomd.xml: [Errno 14] curl#56 – “Recv failure: Connection reset by peer”

Trying other mirror.

The cause of the error here is an outdated or older repository URL.

Solution

Repo setting on the CentOS server can be modified and corrected to resolve the error. PHP installation can go smoothly now. Failures in the DNS resolution can cause problems in loading the repository. The mapping of the repo site to proper IP addresses can be done by using the /etc/hosts files.

The URL has Whitespace

Using whitespaces in between the URL can also cause the cURL 56 error. Whitespaces can be a typo error.

Solution

First of all, we remove the whitespaces present in the URL. After that, we add curl_setopt($ch, CURLOPT_URL, trim($url)); in the PHP settings and if the whitespace character is contained in the URL, then, we can implement the rawurlencode() function in PHP. This will allow you to store and use the URL along with the white spaces.

Conclusion

 We have now covered the causes for the cURL 56 error, including idle server connection, bad repository, and whitespace in the URL. We have also mentioned how to fix the error with the proper steps.