Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

PHP function.file failed to open stream: connection refused

Posted on 2013-12-10
18
Medium Priority
?
3,832 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 7
  • 2
  • +1
18 Comments
 
LVL 84

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 84

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
ATEN's HDBaseT Presentation at InfoComm 2017

Hear ATEN Product Manager YT Liang review HDBaseT technology, highlighting ATEN’s latest solutions as they relate to real-world applications during her presentation at the HDBaseT booth at InfoComm 2017.

 
LVL 17

Author Comment

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

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 84

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 111

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 84

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

Accepted Solution

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

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 27

Assisted Solution

by:skullnobrains
skullnobrains earned 400 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 84

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 84

Expert Comment

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

Featured Post

What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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.

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