View Full Version : Problem with curl

09-09-2009, 12:58 AM
I'm using curl inside of a perl script which requests a webpage from a remote website, which in turn gets processed by the rest of the script. When I run the program from the command line it works absolutely fine, but when I run it through apache it seems to pretend that anything related to the curl request doesn't exist. For instance, if I were to do:

my $result = `curl http://www.google.com`;
print "Content-type: text/html\n\nHELLO WORLD".$result;

it would only show up as HELLO WORLD in a browser, but google's source code shows up if I run it from the terminal. I think this is a synchronization problem, but I'm unsure of how to fix it, any suggestions?

09-09-2009, 01:15 AM
It's an environment problem. The user account that apache runs under has a different environment than your shell account. Try specifying the full path to curl.

Or, my preference would be to use one of the LWP modules, such as LWP::Simple, instead of curl.

use LWP::Simple;
my $content = get("http://www.google.com");

09-09-2009, 02:03 AM
Thanks for the response :P

Specifying /usr/bin/curl doesn't help, if that's what you meant :/ I directed STDERR to STDOUT with 2>&1, and now I get this:

curl: (7) Failed to connect to Permission denied

I was hoping I could avoid LWP and all those, since a) I've got the curl code all set up anyway and b) I need to use POST, which I remember being kind of finicky with perl modules, as opposed to extremely easy with curl.

Why would apache not be allowed to connect to other sites, and how can I change this?

09-09-2009, 02:56 AM
If it's not due to the path environment, then the next most likely cause would be proxy settings. Do you connect through a proxy server? If you're not sure, you can print out your environment settings i.e., issue the 'set' command and look for the proxy setting and/or you can check your browser's proxy settings.

If you are using a proxy, then you can specify the proxy with curl's -p or -x option (I'm not sure which so you'll need to check the man page).

On a side note, while debugging cgi scripts, you should be using the CGI::Carp module, which does the STDERR redirection as well as, in most cases, outputs more descriptive messages.

use CGI::Carp qw(fatalsToBrowser);

09-09-2009, 03:03 AM
Figured it out, SELinux was messin' with me. Turned it off and now everything works fine. Thanks for all your help!

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum