Link to home
Start Free TrialLog in
Avatar of Chris Millard
Chris MillardFlag for United Kingdom of Great Britain and Northern Ireland

asked on

PHP function.file failed to open stream: connection refused

I am running a dedicated IIS on Server 2012. I am trying to get a PHP script running on an external web site that will use the file function to connect to my IIS server. However, the script fails with error:-

Warning: file(http://<my-ip-address:8080/myfile.asp?name=roybridge) [function.file]: failed to open stream: Connection refused in /home/myaccount/public_html/test.php on line 2

The failing line reads:-

$string = file("http://<my-ip-address:8080/myfile.asp?name=roybridge");

Open in new window


If I type that full URL into my browser, then it works properly. If I remove :8080 from the URL in my test PHP file, then it works (but I need it to work on port 8080)

Any ideas please?
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Try using "file_get_contents" instead.  http://www.php.net/manual/en/function.file-get-contents.php  "file()" will return the contents in an array while "file_get_contents()" will return it in a string.
Avatar of Chris Millard

ASKER

Unfortunately I am seeing the same result using file_get_contents()
Is your browser running on the Server 2012?  If it is, can you try that URL from another computer to see it can still connect?
No - the browser is running on a machine external to my location.
but I need it to work on port 8080
What is the business reason that 8080 matters to the application?
Then you must have some kind of filtering going on the Server 2012 machine.  "Connection refused" means that the request did get there, it just wasn't accepted.
@Ray_Paseur - I already have a web site running on Port 80 and 443. I need this one on 8080 (or another arbitrary port).

@DaveBaldwin - I don't have any filtering on. As I said above, if I physically type that URL into an external browser, then it works. If I browse the site internally on port 8080 then it works. This Server 2012 was a new install just a couple of days ago, purely for running this web site. I have opened inbound and outbound TCP ports 80 in Windows firewall. The server is a standalone machine - not even a member server, so no group policies are affecting it. Nothing has been added other than IIS and PHP.
I don't know if this will make sense to you, but I test in a slightly different environment.  

I write my scripts on a PC (Yes, sorry Mac friends) in my office and send them to a shared server by using an FTP client.  The shared server costs me literally pennies per day and I can host several test sites on it.  It's an over-the-internet, nearly live test environment.  

My build scripts send all current components of the site to the server, along with the test data.  Then I visit the site and observe the behavior, or run my automated test data scripts and log the behavior.  This puts my testing environment as close as possible to the live, deployed environment.  

If this cost me a lot of money (more than my clients wanted to bear) it would not be worth it, but I spend less than the price of a beer to have a nearly perfect test environment every single day, and my clients can see the work progress in real time.  And I never have to worry about why a certain port works or not - I can use the ports the way the protocols intended.

Just my $0.02.  Best of luck with the project, ~Ray
I have opened inbound and outbound TCP ports 80 in Windows firewall.
That doesn't help with port 8080.  ??  You need to open port 8080 also if you want to use it.  And make sure that that site in IIS responds to port 8080 (though it sounds like it already does internally).
Sorry - typo - I meant I've opened ports 8080 on the firewall. Port 80 was already open.
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Indeed it would appear that the issue may be at the hosting company end. I have a ticket logged with them and am awaiting a response.
It wasn't apparent to me that your server was at a hosting company instead of on your own premises.  In the name of 'security', hosting companies often block everything they can think of to prevent intrusions.  And that is both incoming and outgoing.  They don't want to be found as the source of problems either.
@DaveBaldwin - sorry if my original question wasn't so clear. When I mentioned "external website" - to me it made sense! That aside, it was in fact your answer above
Any chance that port 8080 is blocked on the server that PHP is running on?
that prompted me to contact the hosting company, so assuming that IS the case, I will be awarding points accordingly :-)
Port 8080 was blocked by the hosting company, but they have now added an exception and it is now working.
Glad you got it working, thanks for the points.