Why doesn't CURL always work?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
RobBroekhuis
Forum Newbie
Posts: 5
Joined: Tue Nov 02, 2004 6:32 am
Location: Allentown, PA, USA

Why doesn't CURL always work?

Post by RobBroekhuis »

I'm using CURL functions in some of my scripts. For the most part, they work great - but once in a while, it will return an error for a perfectly good url. My (relevant) code is:

Code: Select all

curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
   curl_setopt($ch,CURLOPT_USERAGENT,"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)");
   curl_setopt($ch,CURLOPT_TIMEOUT,10);
   curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
   curl_setopt($ch,CURLOPT_URL,$url);
   $page=curl_exec($ch);
   $status=curl_getinfo($ch,CURLINFO_HTTP_CODE);
Almost always works, but for example for this url: http://www.ch2bc.org/
it always returns false (for both $page and $status), whereas the page in question loads quickly into my browser, and doesn't seem to have any funny business. What am I doing wrong?
Post Reply