You are here: Re: Curl fails with Apache - but works in Command Line « PHP Programming Language « IT news, forums, messages
Re: Curl fails with Apache - but works in Command Line

Posted by Andy Hassall on 11/05/06 23:16

On 5 Nov 2006 10:25:29 -0800, "BinnyVA" <binnyva@gmail.com> wrote:

>I am using PHP 5.1.2 with curl enabled. But whenever I try to use curl
>to fetch a url, it fails - 'curl_exec()' returns nothing.
>
>But if I try to execute the same file in CLI - like 'php curl.php', the
>script works properly. However if I try it in a browser, nothing is
>returned.
>
>The code is...
>
>curl.php
>----
><?php
>$ch = curl_init("http://localhost/");
>curl_setopt($ch, CURLOPT_URL, "http://localhost/data.txt");
>curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //Just return the data
>- not print the whole thing.
>curl_setopt($ch, CURLOPT_HEADER, false); //We need the headers
>curl_setopt($ch, CURLOPT_NOBODY, false); //The content - if true, will
>not download the contents
>print curl_exec($ch);
>curl_close($ch);
>----

As there's nothing obviously wrong with the code you posted:

- Are you sure you're using the same instance of PHP? (CLI vs Apache module)
- Is cURL statically compiled into PHP or a loadable module?
- Do you have error_reporting set to the maximum and display_errors turned on
to see any errors?
- You could do some more error checking of the return values, and look at
curl_error()

Could be some sort of environment issue, but not much information to go on so
could be something else.

--
Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация