Solved

PHP function.file failed to open stream: connection refused

Posted on 2013-12-10
18
2,795 Views
Last Modified: 2013-12-14
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?
0
Comment
Question by:Chris Millard
  • 8
  • 7
  • 2
  • +1
18 Comments
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 39709888
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.
0
 
LVL 17

Author Comment

by:Chris Millard
ID: 39709903
Unfortunately I am seeing the same result using file_get_contents()
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 39709935
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?
0
 
LVL 17

Author Comment

by:Chris Millard
ID: 39709941
No - the browser is running on a machine external to my location.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39709994
but I need it to work on port 8080
What is the business reason that 8080 matters to the application?
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 39709997
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.
0
 
LVL 17

Author Comment

by:Chris Millard
ID: 39710035
@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.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39710066
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
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 39710086
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).
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 17

Author Comment

by:Chris Millard
ID: 39710148
Sorry - typo - I meant I've opened ports 8080 on the firewall. Port 80 was already open.
0
 
LVL 82

Accepted Solution

by:
Dave Baldwin earned 400 total points
ID: 39710194
Any chance that port 8080 is blocked on the server that PHP is running on?
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 39710571
There's note about enabling Apps on Server 2012 in this question: http://www.experts-exchange.com/Security/Software_Firewalls/Q_28315331.html#a39710459
0
 
LVL 26

Assisted Solution

by:skullnobrains
skullnobrains earned 100 total points
ID: 39715462
the firewall of the external web site where the php script runs most likely forbids you to issue outgoing connections to port 8080.

i assume you test from a browser in a different location

you can confirm this by either running your php script on your home machine ( which should work if it works in your browser ) or by trying to issue a telnet to port 8080 on the machine running IIS from the location your php script runs ( which should fail with a similar error message )
0
 
LVL 17

Author Comment

by:Chris Millard
ID: 39715945
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.
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 39715982
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.
0
 
LVL 17

Author Comment

by:Chris Millard
ID: 39715997
@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 :-)
0
 
LVL 17

Author Closing Comment

by:Chris Millard
ID: 39719175
Port 8080 was blocked by the hosting company, but they have now added an exception and it is now working.
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 39719216
Glad you got it working, thanks for the points.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
These days socially coordinated efforts have turned into a critical requirement for enterprises.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now