Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Sep 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Problem with curl

    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:
    Code:
    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?

  • #2
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,836
    Thanks
    2
    Thanked 158 Times in 153 Posts
    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.

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

  • #3
    New to the CF scene
    Join Date
    Sep 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 74.125.45.105: 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?

  • #4
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,836
    Thanks
    2
    Thanked 158 Times in 153 Posts
    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.
    Code:
    use CGI::Carp qw(fatalsToBrowser);

  • #5
    New to the CF scene
    Join Date
    Sep 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Figured it out, SELinux was messin' with me. Turned it off and now everything works fine. Thanks for all your help!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •