Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4469
  • Last Modified:

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?
0
Chris Millard
Asked:
Chris Millard
  • 8
  • 7
  • 2
  • +1
2 Solutions
 
Dave BaldwinFixer of ProblemsCommented:
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
 
Chris MillardAuthor Commented:
Unfortunately I am seeing the same result using file_get_contents()
0
 
Dave BaldwinFixer of ProblemsCommented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Chris MillardAuthor Commented:
No - the browser is running on a machine external to my location.
0
 
Ray PaseurCommented:
but I need it to work on port 8080
What is the business reason that 8080 matters to the application?
0
 
Dave BaldwinFixer of ProblemsCommented:
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
 
Chris MillardAuthor Commented:
@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
 
Ray PaseurCommented:
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
 
Dave BaldwinFixer of ProblemsCommented:
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
 
Chris MillardAuthor Commented:
Sorry - typo - I meant I've opened ports 8080 on the firewall. Port 80 was already open.
0
 
Dave BaldwinFixer of ProblemsCommented:
Any chance that port 8080 is blocked on the server that PHP is running on?
0
 
Dave BaldwinFixer of ProblemsCommented:
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
 
skullnobrainsCommented:
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
 
Chris MillardAuthor Commented:
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
 
Dave BaldwinFixer of ProblemsCommented:
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
 
Chris MillardAuthor Commented:
@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
 
Chris MillardAuthor Commented:
Port 8080 was blocked by the hosting company, but they have now added an exception and it is now working.
0
 
Dave BaldwinFixer of ProblemsCommented:
Glad you got it working, thanks for the points.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 8
  • 7
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now