PHP file() - Failed to Open Stream: Connection timed out - php

I'm having a problem troubleshooting this issue about "failed to open stream: connection timed out". There is this application deployed in a server (ip.server.of.main.app). In some part of its code, it is posting data using this code:
$f = file('ip.server.of.another.app/tracker.php?var1=value1&var2=value2')
This ip.server.of.another.ap/tracker.php?var1=value1&var2=value2 is posting the data of the variables passed on the script.
But this line always timed out. In my local pc, when I run a test code containing that line, it didn't timed out and successfully posted the data on the database.
Is there any possible cause why it only timed out when run on the server of the main app?

Related

file_get_contents() failed to open stream: Operation timed out... only on server

When I try to fetch data from website on localhost or on other server, it actually loads the data, but when I try it on production server it returns the warning:
"Warning: file_get_contents(...): failed to open stream: Operation timed out"
But this only happens on that server.
The biggest problem is that it was working yesterday without a problem.
I've already looked up "allow_url_fopen" in php.ini, but it was already on. I tried to use cURL but without success.
try {
$html = file_get_contents("http://www.orsr.sk/hladaj_subjekt.asp?OBMENO=$meno&PF=0&R=on");
}
catch (Exception $e) {
echo $e->getMessage();
}
echo $html;
On localhost and my other server it shows the website, but on that server it catches error
Warning: file_get_contents(http://www.orsr.sk/hladaj_subjekt.asp?OBMENO=Example&PF=0&R=on): failed to open stream: Operation timed out in

PHP File_get_contents error in connection

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.
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.

ftp_put() [function.ftp-put]: Failed to establish connection

I'm trying to ftp upload file using php. Managed to connect via ftp_connect, and ftp_login. That means the connection / credential's ok. However when I try to run ftp_put, it comes out with that error.
ftp_put() [function.ftp-put]: Failed to establish connection
Anyone know what could be causing that problem?

Problem with PHP server

I'm having some problems with my PHP server. Most of the functions when run gives the same error.
Warning: fopen(http://www.ietf.org/rfc/rfc2475.txt) [function.fopen]: failed to open stream:
A connection attempt failed because the connected party did not properly respond after a
period of time, or established connection failed because connected host has failed to respond. D:\inetpub\vhosts\coolfbapps.in\httpdocs\test\merger2.php on line 3
Fatal error: Maximum execution time of 30 seconds exceeded in D:\inetpub\vhosts\coolfbapps.in\httpdocs\test\merger2.php on line 3
The same error comes when i use imagecreate functions, get_image functions.
I talked to service providers but they said I should tell them the cause of this error so that they can rectify it. Please se if any one can make out what changes should be done to server to remove those errors.
CODE USED
$ch = curl_init("http://www.gravatar.com/avatar/95111e2f99bb4b277764c76ad9ad3569?s=32&d=identicon&r=PG");
$fp = fopen("http://www.ietf.org/rfc/rfc2475.txt", "r");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
Sorry for this, but I'm unable to comment yet. You need to post the code that is causing these errors. Are you explicitly requesting that URL?
To debug this, you should logon to the server and attempt to request the file to see if you're actually able to have outbound connections on port 80. To do this on a linux server just run
wget http://www.ietf.org/rfc/rfc2475.txt
.. and see if it fails or not. If it does, you need to talk to your hosting provider / ISP.
If you don't have access to the server you could simply try (in PHP):
<?php
file_get_contents('http://www.google.com/'); // Google so that it's not the same URL
?>
If there's an error, same as above.
The first error (the fopen() one) is caused because of a timeout in the response of the server you're trying to load the data from. i.e. the server is taking too long to respond, so the connection times out.
The second error is that the script is running for too long. PHP has a setting called max_execution_time so that a script can't eat up all the resources on a server. Your server has a setting to allow 30 seconds to execute, or die() with a fatal error.
Seems your server can't connect to these sites. Perhaps your server is not allowed to start outgoing connections or is blocking that outgoing HTTP traffic somehow?
I bet this isn't a PHP problem but instead has to do with your server connection. If you have SSH access, try to open these URLs from the command line without PHP.

File_get_content error

I have tried hosting it on a VPS/web Host and some VPS it works my script and some it gives this error:
Warning:
file_get_contents(http://xip.xxxxx.org/xxxx/../aaaada23.php?user=rawr&host=127.0.0.1&port=3074&time=10&ip=127.0.0.1&power=1)
[function.file-get-contents]: failed
to open stream: A connection attempt
failed because the connected party did
not properly respond after a period of
time, or established connection failed
because connected host has failed to
respond. in
C:\xampp\htdocs\login\boot.php on line
163 Script bad error
Why do I get that error? Could it be DNS?
it means that the domain you're trying to reach is down, unreachable.
it could also mean that the networking/sockets are down on your machine.
Probably winsock error: http://msdn.microsoft.com/en-us/library/aa924071.aspx

Categories