Forum Moderators: coopster

Message Too Old, No Replies

Help with a simple curl script

works on one server, not on other

         

Algebrator

3:28 am on Sep 21, 2005 (gmt 0)

10+ Year Member



I have a following php script:
set_time_limit(0);
$ch = curl_init();
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_MAXREDIRS,100);
curl_setopt($ch,CURLOPT_URL,"h**p://www.mtsu.edu/~devstud2/DSM080.html");
$buffer = curl_exec($ch);
if (curl_errno($ch) == CURLE_OK )
{
echo $buffer;
}
else
{
echo "no";
}
curl_close($ch);

the sample url redirects to another one - I tried the script on different servers - on some it works fine, following the redirect, on others it reports "Cannot find server or DNS Error".
This must have something with PHP settings - if you have any idea what could be causing the error, please let me know

Thanks

jatar_k

4:24 pm on Sep 21, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I'm not really sure

I think the only way to proceed would be to analyze the differences between the 2 servers.

Algebrator

10:32 pm on Sep 21, 2005 (gmt 0)

10+ Year Member



OK, I go the reply from the support:

"We do not open non-standard ports (neither ingress or egress). You will not be able to communicate with any host on port 11064 (or any non-standard port). Port 80 (the standard Web Server port) would, however, be
acceptable."

So if I understood this correctly, the problem doesn't have to do anything with curl or the fact that the url redirects - the site in question is simply sending the data to the port that my host is not listening to. Is that a correct interpretation?

If so, would you have any idea roughly what percentage of sites use such non-standard ports (and why would they do that). If it is generally known that it is a small number of sites, that wouldn't bother me, but if it will disable me from accessing a very large percentage of sites I try to access, I will need to find another hosting company.

StupidScript

11:51 pm on Sep 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Probably cURL is using non-standard port 11064.

Have you tried adding:

curl_setopt($ch,CURLOPT_PORT,80);

to your script? That should force cURL to use port 80 ... even if it is insecure.

Re: why a hosting company would close most of the ports ... security. There aren't many ports that most normal servers need to use, so one thing an admin can do to increase the security of any box is to close most of the ports. There are ~65,000 ports per box, and maybe 5 of them would be used a lot. Different processes would open their own ports as needed, like HTTPD might need a bunch of ports to handle web traffic and start using a limited range of ports to handle the connections. Your provider has probably left open around 200-500 ports for this purpose, but those in the upper ranges, often used by secure or oddball processes are usually "safe" to close. cURL is probably using port 11064 as a security measure of its own, but you may be able to force it to use port 80 (or some other lower range port) which might be open on your server.

Algebrator

12:27 am on Sep 22, 2005 (gmt 0)

10+ Year Member



Thanks, I inserted that line, but it still didn't work.
However, I did some more research and it seems that there are problems with port setting option:
[curl.haxx.se...]
Now, if I could just get the administrator to install the patch...

[edited by: jatar_k at 12:38 am (utc) on Sep. 22, 2005]
[edit reason] linked it up [/edit]

StupidScript

12:29 am on Sep 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Aaaannnnnndddd ... good luck with that! ;)

Algebrator

12:51 am on Sep 22, 2005 (gmt 0)

10+ Year Member



OK - a little bit more messing around - it seems that it has to do with the site that I am trying to access, rather than curl, because the script works fine for some urls, and not with others.
If it were a curl problem, wouldn't I have a problem every time, despite the url that I am trying to pull?

jatar_k

1:36 am on Sep 22, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>> wouldn't I have a problem every time

I would think so, but I can't imagine why a site would respond on non standard ports.

Algebrator

2:25 am on Sep 22, 2005 (gmt 0)

10+ Year Member



...I would think so, but I can't imagine why a site would respond on non standard ports.....

So, am I correct in assuming that this will probably be a relatively rare occurence?

jatar_k

2:48 am on Sep 22, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



hard to say, I didn't think it would happen at all.

StupidScript

4:51 pm on Sep 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Algebrator, have you posted any messages to one of the cURL mailing lists [curl.haxx.se]? While this forum is a superb resource, maybe they've seen more cURL weirdnesses in the mailing lists ...

Algebrator

9:55 pm on Sep 22, 2005 (gmt 0)

10+ Year Member



Thanks for the suggestion!