Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

curl problem 1

Status
Not open for further replies.

davidchardonnet

Programmer
Mar 21, 2001
167
FR
Hello,

The following code works with google url but not with the other url, (the commented line) I get a curl error 28 (timeout).
I don't know why. It looks strange, because i can access it with browsers from outside. and I see the curl GET requests on the web server (because it's a home-hosted webserver)

Can you help me?

Thank you

David
Code:
<?php

$ch = curl_init();

//curl_setopt($ch, CURLOPT_URL, "[URL unfurl="true"]http://89.82.253.168/apache2-default/index.html");[/URL]
curl_setopt($ch, CURLOPT_URL, "[URL unfurl="true"]http://www.google.fr/");[/URL]
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 32000);

curl_exec($ch);

if (curl_errno($ch)) 
{
    print curl_errno($ch);
    print curl_error($ch);
} 
else 
{
    curl_close($ch);
}
?>
 
i'm not sure that you should be testing curl_errno as a conditional. i doubt whether this is the issue however.

try this instead as an error handler
Code:
$result = curl_exec($ch);

if ($result === false){ 
    echo curl_error($ch);
} else {
    curl_close($ch);
}

and in terms of the actual issue: what is the problem you are having precisely? is no data returned? if the same true if you point the curl at a known third party site?
 
then the problem is not php - it is your receiving web site.

if you do a manual get request from a telnet session, what do you get? do you _need_ to use curl or can you use a file_* function?
 
yup, confirmed that it works out of the box. so the problem is unequivocally the setup of your web server and nought to do with php. your server logs should assist with debugging. or failing that it may be a network addressability issue from inside your lan (i.e. the local lookback interface in your router may not be properly functional).
 
No I don't need to use curl. What I need is to make a request from one site to another.
I only know curl, but I am open to any other technique.

My need is:
http get
hosted_webserver -------> home_webserver <--> home_database

I have no control on the hosted_webserver configuration. Maybe the problem comes from it.
You can have a look at its configuration
And as far as the addressability issue inside my lan is concerned, I have no idea of what I have to check to make it functional.
 
The access log indicates that there are GET requests ending with a 200 OK code...
My router is a Comtrend CT-635, is there something to do in it?
 
i'd assumed you were within the same subnet.
i can see no reason why your code would not work. as i said, i have put your code on one of my sites (in france) and it seems to work just fine.

as alternatives to curl, you could simply try file_get_contents() or fopen() + fread()

with both file_get_contents and fopen you must supply the full url of course.
 
The following code gives the error message below:

Code:
<?php
$var=file_get_contents("[URL unfurl="true"]http://89.82.253.168/apache2-default/index.html");[/URL]
print $var;
?>

Warning: file_get_contents( [function.file-get-contents]: failed to open stream: HTTP request failed! in /mnt/147/sdb/d/7/stonejuran/redirect.php on line 26
 
well - it looks as though your web server is not allowing you out of the box. there may be a firewall preventing external access.

however it would seem odd that it allows google. maybe there is a white list of sites held by your ISP. time to invoke their support, i recommend.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top