software development


I opened the browser with this url, http://77.666.555.44:8080/file/test.jsp
That is a sample server address
It works fine in the browser, I see the page.

But when I run it through cUrl it stalls and returns a blank page.
The error message I get from cUrl is “couldn’t connect to host”

Any reason why?
I am new to PHP
If anyone knows the answer please help
I have been stuck on this for weeks.
Any advice will be appreciated.

The PHP code:

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, “http://77.666.555.44:8080/file/test.jsp”);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$response = curl_exec($ch);

if (curl_errno($ch)) {
echo curl_error($ch);
} else {
echo $response;


I am not sure how that could possibly work even in your browser. The specifications for IPv4 addressing don’t allow numbers greater than 255, and the IP address you posted has two octets with values above that number. What is that IP address?

Does that value exist in your HOSTS file as pointing to a different domain? If not, I am at a loss. Whatever the reason you’re seeing something in your browser, you’re simply not going to get a valid curl response from your page on Dreamhost.

Incidently, the code snippet you posted looks valid for all other intents and purposes. Although you’re going to want to execute the “curl_close($ch)” statement whether an error occurs or not.

When working with curl I also assigning the response/error code to a variable, closing the curl connection, and then performing operations on those variables.


Thanks pangea33 for replying =)
that is just a made up server ip.
i took your advice and updated my code but i am still getting the same “could not connect to host” error
Sorry to confuse you with a fake ip address at first. =(


The obvious thing to do is to test your script with a different web page (such as the Google home page or something) so that you can figure out if the problem lies with the script or the remote source.

Max discount on any plan with promocode SCJESSEYTOTAL


Could this be a permission thing to my server?

I tried other url, to replace my server url
The PHP curl code above executed fine with no problem.
I get the print out of the xml result.


I am not sure if you’re hesitant to provide us with the legitimate IP address, or just figured it wasn’t relevant. It would help if you were willing to give the actual location though, it’s hard to troubleshoot the problem without more information. Is there a .htaccess file on that server that might refuse requests from certain sources?


Just a thought - are you trying to access your own computer through your IP address? If so, I would hazard a guess that you are using a router that is blocking access to port 8080. You’ll need to open up that port to make it work.

Max discount on any plan with promocode SCJESSEYTOTAL