473,322 Members | 1,911 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Curl fails with Apache - but works in Command Line

Hi,
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);
----

--
Binny V A
http://www.bin-co.com/php/

Nov 5 '06 #1
4 11989
On 5 Nov 2006 10:25:29 -0800, "BinnyVA" <bi*****@gmail.comwrote:
>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 :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Nov 5 '06 #2
Thanks for the help.
- Are you sure you're using the same instance of PHP? (CLI vs Apache
module)
Yes - I did not compile php myself - I just used what came with the
OS(FC5).
- Is cURL statically compiled into PHP or a loadable module?
I think it is statically compiled - as I said, it came with the OS.
Anyway
the 'Configure Command'(in php_info) had this '--with-curl' - that
means it is
statically compiled, right?
- Do you have error_reporting set to the maximum and display_errors
turned on to see any errors?
No.
- You could do some more error checking of the return values, and
look at
curl_error()
Made some changes to the code...

header("content-type:text/plain");
error_reporting(E_ALL);
$ch = curl_init("http://localhost/");
curl_setopt($ch, CURLOPT_URL, "http://localhost/data.txt");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);thing.
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_NOBODY, false);

$response = curl_exec($ch);
if(is_int($response)) {
die(curl_error($ch));
}

print "'$response'\n";
print_r(curl_getinfo($ch));
curl_close($ch);

----------------
Now the response is this...

''
Array
(
[url] =http://localhost/data.txt
[http_code] =0
[header_size] =0
[request_size] =0
[filetime] =-1
[ssl_verify_result] =0
[redirect_count] =0
[total_time] =0
[namelookup_time] =0.000296
[connect_time] =0
[pretransfer_time] =0
[size_upload] =0
[size_download] =0
[speed_download] =0
[speed_upload] =0
[download_content_length] =0
[upload_content_length] =0
[starttransfer_time] =0
[redirect_time] =0
)
--------------
Could be some sort of environment issue, but not much information
to go on so could be something else.
What information do you need?

--
Binny V A
http://binnyva.blogspot.com/

Nov 6 '06 #3
Hello everyone,

I have solved this problem - the cause was SELinux.

After a while, I gave up on curl and tired to access the url using
fsockopen - the script failed with a 'Permission denied' error. A
search later, I found this was due to SELinux.

So I disabled SELinux...
Open /etc/selinux/config
Add the line 'SELINUX=disabled'
Reboot the system
Note : You have to be root to do this.

Now both fsockopen and curl is working fine.
--
Binny V A
http://www.bin-co.com/php/ - Many PHP functions
Nov 6 '06 #4
On 6 Nov 2006 09:27:04 -0800, "BinnyVA" <bi*****@gmail.comwrote:
>I have solved this problem - the cause was SELinux.
Ah - thanks for posting the solution, may be useful to other who hit similar
mystery failures.

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Nov 6 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Haluk Durmus | last post by:
Hello I checked out openssl,mm,apr,apr-util,apache 2,curl,libxml and php from cvs. php couse an ERROR I did the following steps:
1
by: Bib | last post by:
I'm working on a box that allegedly has curl support, but when I run a script that access curl, I get this error: Fatal error: Call to undefined function: curl_init() in...
3
by: Chris Fortune | last post by:
# uname -a Linux stargate.mxc-online.net 2.4.20-021stab022.2.777-smp #1 SMP Wed Jul 28 17:12:37 MSD 2004 i686 i686 i386 GNU/Linux I recompiled PHP with mcrypt, openssl, and curl phpinfo():...
1
by: Rory | last post by:
I'm just starting to use cURL and having trouble accessing https pages. All I want to do at this stage is get an https page and display it, just to test the https get is working. However, I always...
0
by: jsaint | last post by:
I'm using php 5.1.2 on apache 2.0.54 and am trying to use curl to connect to an ssl server. Curl works fine using http, and the command-line client works with https. But, in php, I just get error 7...
4
by: Terry | last post by:
I'm using curl to invoke a php script on the same site/server. It works great, but if I call it again while it's still running, nothing happens. Why? Can that be fixed? Why use curl? To make...
4
by: rottmanj | last post by:
I am working on a revamp of a previous application that I have written in coldfusion. The application deals with RETS data. The issue that I am having is with using the curl option HTTP_AUTH and...
11
by: Flexor | last post by:
I have a php script that runs from command line and makes an https request to paypal, using curl. It works fine if I run it from a web page. It fails if I run it from CLI. The error I get from...
5
by: DustinP | last post by:
I have installed PHP5 as ISAPI several times per every single guide I could find in the first 50 pages of results on google.. Server is Windows 2008 runing IIS7, phpinfo works and tells me the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.