• Status: Solved
• Priority: Medium
• Security: Public
• Views: 2707
• Last Modified:

# cURL & fopen() do not work on internally hosted server

I have an IIS7 web server hosted internally and I can't seem to get the fopen() or cURL PHP extensions working properly.

I have no firewall turned on, but am still not able to get things to work.

Here's what I get when trying to use cURL transport for Joomla or WordPress:
Please wait...

An Error has occured: couldn't connect to host

Here's what I get when trying to use fopen() transport for Joomla or WordPress:
Please wait...

An Error has occured: Could not open handle for fopen() to http://tools.dd32.id.au/wordpress/core-control.php

Can someone please guide me through this process?  What information do you need to get started?
0
Andrew Derse
Asked:
• 16
• 12
• 2
2 Solutions

Fixer of ProblemsCommented:
What versions of the server and PHP are you using?  I don't see 'core-control.php' in either of my Wordpress installs so it must be something you wrote.  Can you show us the code so we can see how you are using it?
0

IT ManagerAuthor Commented:
PHP Version: -> 5.3.6
Web Platform Version: Windows -> IIS7.5

core-control.php was a plugin I installed for Word Press to help me troubleshoot why the cURL and fopen() transports aren't working for any of my websites.

Attached is the zip file for the plugin.
core-control.1.1.zip
0

IT ManagerAuthor Commented:
I know this has to do with how my web server is setup, but I've tried almost everything to get it to work, but have not been successful.
0

IT ManagerAuthor Commented:
I might be getting closer.

My server can't ping 72.233.56.139, but I can open up firefox and navigate to 72.233.56.139 just fine...
0

Fixer of ProblemsCommented:
Are you running Windows Server 2008 or Windows 7?  I downloaded your zip file and I don't find fopen() in there anywhere.
0

Fixer of ProblemsCommented:
That just means ping is blocked.  Has nothing to do with web access.
0

IT ManagerAuthor Commented:
Windows Server 2008.

The zip file is just a plugin that was recommended for me to use.  My problem is that I can't browse any new themes or plugins from within Word Press and I can't upgrade Joomla through their new process because I can't seem to include or open http:// page calls through curl or fopen().

Most of the sites say I need to enable them, but they are both enabled in my PHP.ini file...they just aren't working for some reason.  Other sites say I need to turn off firewall or make an exception...done...same results...

Now I'm just hoping the experts can help troubleshoot why I can't do some of these things...and I'm 100% sure it's something with my web server...just don't know what to try next...
0

IT ManagerAuthor Commented:
Here, this code is my test code...the result I get is: Nothing.

<?php
$file="http://www.google.es";$gestor = fopen($file, "r") or die ("Nothing"); ?>  0 Fixer of ProblemsCommented: I'm getting confused. What program or file or process are you running when you get these errors? 0 IT ManagerAuthor Commented: Straight up connecting to a file now... It's a temp file I'm creating in the root of the site...test.php...with this code in it to test functionality...and it returns an error. 0 Fixer of ProblemsCommented: Try this. Save it as "curlphp.php". It uses curl to load the text part of "www.google.com" and displays it in your browser. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>PHP curl test</title> </head> <body> <?php // create curl resource$ch2 = curl_init();

// set url
curl_setopt($ch2, CURLOPT_URL, "www.google.com"); //return the transfer as a string curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);

// $output contains the output string$output = curl_exec($ch2); // close curl resource to free up system resources curl_close($ch2);
echo $output; ?> </body> </html>  0 Fixer of ProblemsCommented: And try this for fopen(). <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Untitled</title> </head> <body> <?php$file="http://www.google.es";
$gestor = fopen($file, "r") or die ("Nothing");
$data=''; while(!feof($gestor))
$data.=fread($gestor,1024);
fclose($gestor); echo$data;
?>

</body>
</html>

0

IT ManagerAuthor Commented:
Thanks.  I will try this first thing in the morning.
0

Fixer of ProblemsCommented:
Both of those test programs work on both my IIS 5.1 on XP and IIS7 on Godaddy hosting.
0

IT ManagerAuthor Commented:
Alright, tested both and I got a blank screen on the curlphp.php and Nothing on the fopen() code.  They probably work fine on a hosted server, but mine I've built from the ground up and just need to know how to configure my server properly to get two transports working.
0

Fixer of ProblemsCommented:
What does work on your server?  Can you run phpinfo(); to see what PHP thinks is set up and working?
0

IT ManagerAuthor Commented:
Yes, PHP is running on my server.  Here's what it says...
phpinfo.pdf
0

Fixer of ProblemsCommented:
I don't see anything in your phpinfo page that would cause your curl and fopen to not work.
0

IT ManagerAuthor Commented:
Exactly...that's what I thought, but it's not working...so that's why I created this question.  To get an expert to help me through the process of making sure my IIS7 server and settings were set properly...
0

Fixer of ProblemsCommented:
You need to click on "Request Attention" above.  I'm out of suggestions.
0

IT ManagerAuthor Commented:
No problem, will do.
0

ConsultantCommented:
This sounds like a network issue to me. You should be able to ping that IP address. I just tried it from my location and was getting a response, so ping shouldn't be blocked.

So you said you can run Firefox FROM the server and you can hit the IP successfully? Or are you using Firefox from outside?

My guess is that either the web server has somehow been locked down so that it doesn't allow outbound network traffic, or else you have network connection problems.
0

IT ManagerAuthor Commented:
The server itself goes through a proxy...could that be the issue?
0

Fixer of ProblemsCommented:
Yes, I believe that it could.  Do you have any way to bypass the proxy?
0

IT ManagerAuthor Commented:
I am asking the Networking guy to make an exception for that single IP address.  My local machine environment does not go through a proxy...so all works well for my local environment with your code...but not the server...and that DOES sit behind a proxy...

This could be it :)

I'll see what happens when we bypass the proxy server on the server machine.
0

ConsultantCommented:
Yes, that sounds very likely like the issue, if a proxy is required. To use a proxy with PHP, you'll need to wrap the fopen call in a context. Look at the last parameter:

http://php.net/manual/en/function.fopen.php

You would do something like this:

$proxyIP = "192.168.1.123";$proxyPort = 80;

$context = stream_context_create(array( 'http' => array( 'proxy' => 'tcp://{$proxyIP}:{$proxyPort}' )));$fp = fopen("72.233.56.139","r",false,$context); .... rest of the code is the same ... cURL has its own option for setting a proxy. Search this page: http://us.php.net/manual/en/function.curl-setopt.php ...for the word "proxy" and you'll see the parameters you need to set to make cURL use the proxy. 0 IT ManagerAuthor Commented: This last piece of code did not work with our server, please see my updated page...and I'm still waiting to hear back from the networking guy to see if he can set the server's ip address to bypass the proxy completely. test.php 0 Fixer of ProblemsCommented: This is what I get when I run that code: Warning: fopen(72.233.56.139) [function.fopen]: failed to open stream: No such file or directory in C:\Inetpub\wwwroot\ee\PHP Fopen Test 3.php on line 19 Nothing If I change that to "http://72.233.56.139", I get: Warning: fopen() [function.fopen]: php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\Inetpub\wwwroot\ee\PHP Fopen Test 3.php on line 19 Warning: fopen(http://72.233.56.139) [function.fopen]: failed to open stream: php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\Inetpub\wwwroot\ee\PHP Fopen Test 3.php on line 19 If I simplify it to this, it works and shows Wordpress.org. You do need the 'http://' in the file spec or it will look for a local file by the name of '72.233.56.139'. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>PHP Fopen Test 3</title> </head> <body> <h1>PHP Fopen Test 3</h1> <?php$file="http://72.233.56.139";
$gestor = fopen($file, "r") or die ("Nothing");
$data=''; while(!feof($gestor))
$data.=fread($gestor,1024);
fclose($gestor); echo$data;
?>

</body>
</html>

0

IT ManagerAuthor Commented:
Like I mentioned before...works fine in my test environment (not behind a proxy)...just need to get my server out from behind a proxy and test then...

Will keep you all updated.
0

IT ManagerAuthor Commented:
It was the proxy.
0

## Featured Post

• 16
• 12
• 2
Tackle projects and never again get stuck behind a technical roadblock.