|
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]
|