I have a problem with a PHP script triggering a "connection refused" message. Im trying to execute file_get_contents('http://some_domain'). I have also tried fsockopen(), socket_create() and curl_exec() but they all result in "connection refused" on some specific sites that I want to reach. (i.e. its not a general problem).
The resources do exist and I can contact them via my browser.
If I run the PHP on my localhost server, it connects OK
The problem is only apparent if I run the code on either of my remote servers
The problem only occurs with some sites, not all sites
The code worked OK until a few weeks ago
A common factor is that the three sites Im trying to reach are all running web servers behind domestic broadband routers that I installed (but with different broadband providers). But - as I said above - I can access them all from my browser, and the code worked until a few weeks ago. As far as I can see its not a firewall issue in the routers.
Im not sure what all that means - could there be some firewall issue on some intervening machine? How could I tell?
The answer to this turned out to be nothing but a server firewall problem. A new rule set had been loaded into iptables. Hopefully this will be useful to future enquirers - check iptables and your server log and save yourself a lot of time!
Related
I've been developing a Laravel 4 site on my work machine for over a year. Today I began receiving a The connection to localhost was interrupted error whenever I attempt to access the site. At the moment I'm just trying to find applicable log files that might tell me what's failing, and would appreciate suggestions from those more versed in tracking down this kind of failure. You'll see one possible cause below, but I still need to find some error logs to have any idea how to fix it. Here are some pertinent details:
I'm running Windows 7, IIS 7.5, PHP 5.5.1, and Laravel 4.1.23.
The application is accessed via https://localhost/ephy, and IIS is configured to deliver the ephy directory over SSL.
http://localhost/ephy correctly returns a 403 error indicating that the page must be accessed over SSL.
When copies of phpinfo.php (containing just a call to phpinfo() ) are placed in both the root directory and the ephy subdirectory, http://localhost/phpinfo.php executes, while https://localhost/ephy/phpinfo.php returns the connection reset error.
The application itself is executing successfully on the production server, so the PHP code is valid.
Yesterday I installed Office 2013, uninstalled Office 2010, uninstalled Office 2013, and then reinstalled Office 2013 (in that order). I also installed 2 GB of memory, because Outlook 2013 kept hanging.
The site was accessible as of 4pm yesterday, after all of that installation activity was already over.
I've made no changes to the application or the computer configuration since 4pm.
I've restarted the computer several times.
I've checked the files in C:\inetpub\logs\LogFiles , but they don't show any error messages.
So, I know PHP is running successfully and that the issue is specific to serving the application directory itself, but that's as far as I've been able to get. Recommendations on where to find (or how to generate) logs which would indicate what's happening, or any insights into the failure itself, would be appreciated.
Ok, after finally finding the magic combination of search terms on Google (ERR_CONNECTION_RESET localhost iis 7, for those who are curious, the first term being the error message from Chrome specifically), I was able to determine that this behavior can be caused by not having the self-signed security certificate correctly bound to the site in IIS. As I said, the site had been working successfully, but with the software updates I'd done something probably got borked (maybe adding the memory changed the computer's identity such that the certificate was no longer valid? I don't know).
So, I followed the instructions at http://weblogs.asp.net/scottgu/tip-trick-enabling-ssl-on-iis7-using-self-signed-certificates (with a bit of adjustment because apparently the binding has to be done at the default site level in IIS 7.5, rather than at the individual site level), whacking and replacing the existing certificate and SSL binding in the process. The site is now working again on my box.
So, in a nutshell: if you're running SSL on localhost under IIS and you get "connection to localhost was interrupted" messages, try redoing the certificate and binding.
Man, glad that's over...
UPDATE
So I completely disabled my server's firewall and it appears to be the culprit. I had tried to disable certain rules before but disabling the whole thing worked. Very frustrating, but problem solved I guess... I think the key indicator that it was the firewall was because it happened at exactly midnight when my server likes to apply updates and such.
This is pretty strange to me, I have a server downstairs that hosts my websites and MySQL servers and it has been running for years without many issues. I have 2 routers bridged together behind my modem and my server is behind one of them. All other devices connect via WiFi. All of the proper ports are open on the router and I have users configured in MySQL that haven't changed and have been working fine this whole time.
So last night I was working on a project and I decided to sync everything with a backup on my SkyDrive. I have a scheduled backup for MySQL that runs at midnight (daily) and it just turned over to midnight so I decided to open my network and watch the file get populated before I sent a copy to my SkyDrive. After the backup was complete (which it did successfully), I was going to continue to work on my program but all of a sudden I can no longer connect via my local network to the MySQL server. I'm using PHP and my connection string never changed and all other MySQL admin tools don't connect. The live site works fine, so MySQL was definitely running and working but no remote connections were being accepted. Why is this happening all of a sudden?
Things I've tried :
I did notice that my logs were packed full of BINLOG errors so I turned off the binlog since I recently turned it on (a couple weeks ago).
Restarting MySQL
Turning off Windows Server 2008 firewall (temporarily)
Connecting from a different device (mobile phone, tablet), no luck
Temporarily allowing port 3306 on my router
Checked server logs for intrusion attempts, none present...
Setup :
PHP 5.4 on local machine and server
Windows Server 2008 Enterprise (on server...)
MySQL Version 5.5.25a
Does anyone have any clue as to what's going on here? I'm going to reboot my server when the load is low and see if this helps any, I will update this once it comes back online.
So I completely disabled my server's firewall and it appears to be the culprit. I had tried to disable certain rules before but disabling the whole thing worked. Very frustrating, but problem solved I guess... I think the key indicator that it was the firewall was because it happened at exactly midnight when my server likes to apply updates and such.
Ok, so I have set up a installation of lamp and mediawiki on my machine with the path http://localhost/mw/. I then proceeded to install windows on a virtual machine so i could test mediawiki installation with Internet Explorer. So i set the appropriate $wgServer setting to my host IP addr which was reachable from the virtualbox client.
First i accessed http://x.x.x.x/ and got a directory listing, yay it works. right?.... NO..
I then proceeded to access http://x.x.x.x/mw/ (mediawiki path), and to my suprise, IE was just loading on recieve. Several hours went by, and still IE was loading the page... No connection timeout, no recieve timeout. just loading.. forever and ever...
When trying to investigate what was really going on here, i downloaded the cli utility cURL. and proceeded with the command: curl -v http://x.x.x.x/mw/index.php/Main_Page. I was able to retrieve the page, however the result was mind blowing!
First off, mediawiki reports that the page was rendered quite fast (as read from the recieved html source)
Served in 0.356 secs.
Curl on the other hand;
* 14542 bytes transfered in 764.580 seconds (19 bytes/sec).
This suggests to me that for some reason the path /mw/... has a very slow transfer rate. All the other sites works just fine, but not /mw/
And since i never got a connection timeout or receive timeout in IE im guessing that i'm recieving byte for byte at a very slow rate, and it does this for all the resources on the page im trying to get.
And to make things even more interesting, the host machine can access /mw/ without any problems at all. I also tried connecting with another computer on the network (not a virtual machine), and it also suffered the same issue with endless loading.
Any ideas on what is going on here?
The issue seems to be traced back to xdebug module when configured with auto connect back.
Removing xdebug.xdebug.remote_connect_back in xdebug config solved the issue.
Recently few days I run into a weird problem of php not able to connect to mysql on RDS, while manual connections are fine.
So I have several php scripts sitting on our server which is hosted on EC2, and these scripts are called by the clients to communicate with a mysql server sitting on RDS. The scripts are setup so that if any connection error occurs, they would send email notification to me.
So for the recent few days I'm receiving thousands of error emails from my scripts, at the first few days the errors were simple saying the server host is not recognized, but I am sure the address is correct. And now the errors are almost all saying "Host XXX is blocked because of many connection errors, unblock with mysqladmin flush-hosts..." If I flush the hosts, the errors come back to me after a while.
What confuses me the most is that, I cannot reproduce the problem! I tried connecting to the RDS server from my EC2 server through command line and through test php scripts... They all work! If I manually invoke the scripts sending me error emails, they work too! Looking at the RDS monitor, all stat looks normal, CPU is bouncing around 50%, and plenty of hard drive space.
So I'm totally confused right now... Can anyone provide me some insight about how to solve this problem? I don't even know where to look at now...
you need to check your connection to the mysql server and check for errors. Until then you can cron a "flush hosts" to temporary fix the issue. Be aware that this should be used only as a temporary fix.
I have a server that's returning an unexpected, intermittent error and wondering if anyone has either experienced it before or can guess what might be going on. My search has so far has been unfruitful.
Im connecting to a remote mysql server using mysql_connect() in the usual way, but for the last 2 weeks (couple of times a day) the connection to the database fails and I get an unable to connect to socket error?
Error: 2002 - Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
Obviously this is unexpected as Im trying to connect to a remote host. Does mysql_connect default to localhost if the remote host is unavailable? I've not known it to do that, and nothing in the docs that say it does.
There doesn't seem to be any pattern to the failed connections, various files and it happens at all sorts of time of day. Im thinking it might be network traffic related, because if you refresh the page straight away it connects fine, but am confused as to why Im getting an unable to connect to socket error.
the database provider has checked and are unable to find an issue with the server itself.
anyone have any ideas?
Im sure it doesnt default to localhost, and im also pretty sure that it is the remote server sending you the error message. So it's "Local" on your mysql server, not local on "your" server.
In this case its probably due to downtime on the remote server.
Gr.
ok, facepalm moment... after this hitting me for ages I finally found why mysql_error() was reporting the socket error. in my code there was a mysql_select_db() that I didnt notice and it was that, thats reporting the socket error as there is no open connection for it to use.
actual error the mysql_connect is reporting is (2003) Can't connect to MySQL server on 'mysql.hostname.tld'. Im still leaning towards some sort of DNS lookup/network traffic issue, Im currently using the IP address to connect to see if that errors.
But as far as this question is concerned, the answer is "Im a numpty".
Have a look at this
Had a similar thing a while back.
Are you connecting from home? The reason I ask is that my ISP likes to mess around re-assinging IP addresses to my home account, and I have an IP authorization on my remote MySQL.
I think I opened up the IP connnection limitation thing to a string that was IP Addresses for my region and that solved the problem.
If you're running Windows, there might be too many connections already, if so go to http://dev.mysql.com/doc/refman/5.5/en/can-not-connect-to-server.html#can-not-connect-to-server-on-windows and have a read.
Else, perhaps someone someone may have removed the Unix socket file that mysqld uses (/tmp/mysql.sock by default). For example, you might have a cron job that removes old files from the /tmp directory.