1

I have a php file and all it contains is

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

echo file_get_contents("http://mywebsite.com/javascript-function.php");
?>

And for some reason it displays the following notice:

Notice: file_get_contents(): send of 24 bytes failed with errno=104 Connection reset by peer in /home/sites/mywebsite.com/public_html/index.php on line 6 Notice: file_get_contents(): send of 2 bytes failed with errno=32 Broken pipe in /home/sites/mywebsite.com/public_html/index.php on line 6

I have never come accross this message before so I have no idea what to do to solve it.

I have also tried using cURL but it outputs nothing and no error message.

11
  • Take a look at the error log file of the http server on mywebsite.com. Commented Jan 23, 2016 at 13:48
  • 1
    You mean, the php-script tries to fetch its own output via http? What are you trying to do? Connection reset by peer means, the remote closed it without reading all data from the socket Commented Jan 23, 2016 at 13:48
  • 1
    Probably target web site using a user-agent policy or something like that, or your hosting's IP address is blocked on target computer. Commented Jan 23, 2016 at 13:48
  • 1
    I'm trying to create a bunch of php function files. It's a little complicated but I'm trying to make a file which will output javascript code because I am unable to put a javascript variable to PHP so I thought this method might work. On the file I'm trying to get, it has a function and at the end it has document.write(function-result); Does this method not work? Commented Jan 23, 2016 at 13:51
  • @Acidic Maybe it works when done right, I didn't get it fully, but in any case there should be no need to fetch it through http. Better load it from a local file Commented Jan 23, 2016 at 14:01

1 Answer 1

2

A connection reset by peer error occurs in a datastream connection when either the remote host you are connecting to (i.e. mywebsite.com which you specified in the call to file_get_contents) terminates the socket connection on their end before the client is finished sending the request, or when the local network system detects a failure in connecting.

Some common root causes could be a firewall rule that is blocking the connection on either end or possibly a miss-configured web server. One way to narrow down the problem is to attempt accessing the same URL from a web browser on the same client that this script was run when the error occurred. If it works as expected, at least you know, it's not a firewall issue on the client. Begin digging into the web server's config files to troubleshoot the problem further. However, if the same problem occurs in a web browser then you should begin looking into your firewall rules on that client as well as the host's firewall rules if any.

Sign up to request clarification or add additional context in comments.

9 Comments

Yeah I've tried heaps of different methods but I think it's my web host's fault. Some sort of setting/feature that needs adjusting I guess.
The firewall rule would not lead to Connection reset by peer. Connection refused or Connection timed out would be possible.
Well I have no idea what it is then, I've tried just simply putting a .txt file in the root of my domain and using file_get_contents for it but the exact same error is showing.
So I emailed my web host. They reply with: "The only restriction we have is that our servers don't allow loopback connections (i.e. network connections back to themselves).". This is my problem I'm assuming?
@Acidic Correctamundo ;) But as I said above, it shouldn't be necessary anyway.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.