After reading the following links:
get url content PHP
file_get_contents failed to open stream: Connection refused godaddy server with remote connection server
PHP file_get_contents() returns "failed to open stream: HTTP request failed!"
I'm having a problem with the function file_get_contents or even curl in one of my servers at hostgator, they are not working, returning the PHP error failed to open stream: Connection refused. I've tried cURL with USERAGENT set with no result too. It's a simple weather service that I'm creating, it returns the altitude, wind direction, speed and temperature on a certain coordinate of the globe.
Return sample: 30000;221;2;-32;1;
In the other side (request side), I have a web server running IIS 7.5, with all router firewalls, computers firewalls and antivirus softwares disabled only for testing, and is still refusing the connection ONLY for the hostgator servers. I've tried the same code in other web hosting providers, and the code is working properly.
This service will handle a lot of requests per minute, and this seems to me that something has blocked my connection between hostgator and my server due to the number of requests. But I don't know where!!
The page is perfectly accesible via browser.
This is my enviorioment at the hostgator side:
allow_url_fopen: On
allow_url_include: On
OpenSSL: Enabled
Here is my PHP code:
$datalink = "http://#####.########.###:8280/weather.php?waypoint_lat=-10.981925&waypoint_lon=-37.077377&altitude=30000";
$weather_layer = file_get_contents($datalink);
echo "Layer ($datalink):" .$weather_layer."<br>";
Isn't Hostgator blocking the requests because of the DDoS protection? Give them a call, my hosting provider was blocking connections to my other server because they were thinking it was some hacker DDoSing using my hosting.
Also, there might be problem with the port in URL - Hostgator cannot proccess it?
Related
I work with 2 servers one is my production server other is my resource server.
I cannot connect to my resource server from my production server over ftp.
I can connect to other servers from my production server.
I can also connect to my resource server from my localhost or filezilla.
I use this code to connect :
$conn_id = ftp_connect("resource server ip", "21", "5");
if ($conn_id) {
echo "connected";
ftp_close($conn_id);
}
print_r(error_get_last());
I don't get any output when I run this script on server(no error).
On localhost it runs no problem.
What can be the problem with this? Is this something that server admin has to resolve? Thanks for help.
You should first check from commandline, whether it's a networking/OS issue or not.
So if you've got shell access to the production server try connecting to the resource server via the commandline ftp client.
If that does not work, you've got a network / firewall / access control problem, not related to php or your software, and you should talk to the sysadmin.
If it does work, then the problem is in your stuff, and you should set the log levels to high, and run this script from commandline, also check the logs of php, php-error, syslog and the resource servers ftp access log and syslog too.
Note: ftp is a not-too-exact beast, the servers and clients have a lot of workarounds built in to treat each other in a way, that works somehow. There could be issues from active (multiple back-and-forth connections) and passive mode (it's like http), also with ls formats and timestamps, timezones and ports.
Also some servers only support ftps (ftp with ssl) - which is not the same as sftp (file transfer over ssh - port 22).
Your production server probably has some firewall rules, and your connection get caught on that, to debug this, please use the commandline ftp client, and/or nmap / netcat.
Hi Here's what i am trying to do .
$contents = file_get_contents('http://123.34.56.123:3000/?location=Example'); //Not the original ip
//Node script running on port 3000
Everything is working fine on localhost and when i access this url directly from browser but on my web server i ma getting this error
file_get_contents(http://123.34.56.123:3000/?location=Example) Failed to open stream: Connection timed out in ....
And i have tried connecting with curl , sockets and file stream but everything getting the connection is timing out though it's working fine on my local server
I have also used ini_set('max_execution_time', 300); but it didn't help anything
Note : file_get_contents('http://www.google.com'); Works fine on the web server
Anyone can help me understand why i am getting this error ? i have tried almost everything i could to fix this issue.
First of all you need to check that whether the content which you are fetching from resource is encoded or not, means if the content is encoded with JSON then you need to use json script to decode it and after that you will be able to be get the content..
also check the resource URL and the port of the server that you are using.
If your port 3000 is blocked then it also not works fine.
I though it will help you.
Seems like the server i was using was blocking connection on port 3000 , and it makes complete sense as normally web host use 80 and 443 port only to make i/o connection . I contacted with my web host they unlocked the 3000 port and it's working perfectly now .
We send some files across to a third party with a PHP cron job via FTP.
However sometimes we get the following error:
ErrorException [ 2 ]: ftp_put(): php_connect_nonb() failed: Operation
now in progress (115) ~ MODPATH/fileop/classes/Drivers/Fileop/Ftp.php [ 37 ]
When I say "sometimes" I mean exactly that; most times it goes across fine but about 1 in 5 times we get that error. It's not to do with the files themselves, because they will go happily if we try again.
We've found similar issues online - relating to a bug in PHP with NAT devices or to do with firewall configuration but again the implication is that if this were the case it would never work.
So, why would this work some times and not others?
ftp_set_option($ftpconn, FTP_USEPASVADDRESS, false);
This line of code before setting passivity of the connection ftp_pasv($ftpconn, true);
Solved my problem
FTP(S) uses random ports to set up data connections; an intermittent success rate indicates that not all ports are allowed by a firewall on the client and/or server machines. The port range for incoming (PASV) data connections can be set in the FTP server.
This page has a nice summary:
The easy way is to simply allow FTP servers and clients unlimited
access through your firewall, but if you like to limit their access to
"known" ports, you have to understand the 4 different scenarios.
1) The FTP server should be allowed to accept TCP connections to port
21, and to make TCP connections from port 20 to any (remote ephemeral)
port.
2) The FTP server should be allowed to accept TCP connections to port
21, AND to accept TCP connections to any ephemeral port as well!
3) The FTP client should be allowed to make TCP connections to port
21, and to accept TCP connections from port 20 to any ephemeral port.
4) The FTP client should be allowed to make TCP connections to port
21, and to make TCP connections to any other (remote ephemeral) port
as well!
So, I'm writing this answer after doing some investigation on my FTP server and reading the link you provided elitehosts.com.
I'm using FileZilla FTP server, and there is a specific setting that I had to enter to make it work. Going into the server settings, there is an area titled "Passive mode settings". In that dialog, there is an area titled "IPv4 specific", and within that area there is a setting labeled "External Server IP Address for passive mode transfers:". It's a radio button selection set, and it was on "Default", but since the FTP server is NAT'ed, I changed that radio selection from "Default" to "Use the following IP:" and entered in the external-facing IP address of my gateway provided by my ISP.
After I set this up, it worked! Not terribly sure if your FTP server is NAT'ed, but I thought I would provide the answer on this thread because it seems related.
In addition to Cees answer, I am running vsftp on ec2 and had to comment out the listen_ipv6=YES, listen=YES then "service vsftpd restart".
Although documentation says it will listen on ipv4 as well it wasn't and this resolved the issue.
For me all I had to do was to remove the ftp_pasv( $ftpconn, true ); and everything worked perfectly. I'm not yet sure why but I am trying to find out and I will surely come back when I do get the reason behind it.
This should be a comment under jj_dev2 comment, but I cannot add one due to reputation. But maybe it will be helpful for someone, so I post it here.
We had the same issue as described in the original post. In our case it worked with many customers - except one.
The solution in jj_dev2 comment did work for us. So we investigated what does ftp_set_option($conn, FTP_USEPASVADDRESS, false) actually do. And based on that we found out that in fact customer's FTPS server was configured incorrectly.
In response to PASV command (ftp_pasv($conn, true)) FTP server returns an IP address which the PHP FTP client then will use for data transfers. In our case the FTP server was returning an internal IP address and not the public IP address that we connect to. Customer had to fix their FTP server settings so FTP server would send external IP address in the PASV command response.
My project uses PHP JavaBridge, I have installed WAMP, JRE 6.0, and Tomcat 6.0.32
I can now access http://localhost:8080/ successfully but when I run my PHP site it gives me the following error
warning: fsockopen() [function.fsockopen]: unable to connect to localhost:8080 (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. )
Can anyone please help me with this issue?
EDIT
Forgot to mention that I am using Windows 7
My comment above worked as a solution and hence this answer, so that in future others get it.
Can you 127.0.0.1:8080 instead of localhost:8080? See what do you get?
fsocketopen takes the hostname and it should be a valid domain, in your case, (in general) it could be a valid domain as long as you have an entry for localhost in your hosts file (C:\Windows\System 32\drivers\etc\hosts). See if you have something similar to that.
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.