0

I have a CGI (perl) script that is attempting to call curl using the open command:

@curl = ('/usr/bin/curl', '-S','-v','--location', $url, 
                          '-H', 'Content-Type:'.$content_type,
                          '-H', "Authorization: $authorization",
                          '-H', "X-Gdata-Key:$gdata_key",
                          '-H', "Content-Length:$content_length",
                          '-H','GData-Version:2',
                          '--data',"\@$filename");

And then executed like so:

open CURL, "-|", @curl;

The program works perfectly from the command line, but when I try to run it in the browser, the page ends up timing out.

What do I need to change on my server or in my script to get this to work properly?

4
  • 2
    Might want to ask this on Server Fault Commented Nov 30, 2009 at 17:44
  • 4
    What's in the error log? Chances are good that there's something missing in your web server's $PATH. Commented Nov 30, 2009 at 17:46
  • 1
    This is pretty easy to do in pure Perl. Is there a reason you want to use curl instead of LWP::UserAgent, etc? Commented Dec 1, 2009 at 16:33
  • @brian: Because curl is better! Commented Dec 1, 2009 at 16:35

3 Answers 3

1

You should check if the open succeeded and also attempt to close the pipe explicitly, check for error. In case of error, die with the error message. Then find the error message in the server error log.

Sign up to request clarification or add additional context in comments.

2 Comments

Sinan, Thank you. I tried this, and the program hangs on the open command (I tried exiting both before and after to discover what was hanging the program). The error log file has the following which I am still trying to googe/figure out: [Mon Nov 30 14:59:07 2009] [error] slurp_filename('/var/www/vhosts/mydomain.net/httpdocs/youtube/youtube.pl') / opening: (2) No such file or directory at /usr/lib64/perl5/vendor_perl/5.8.6/x86_64-linux-thread-multi/ModPerl/RegistryCooker.pm line 540
@Miriam Raphael Roberts: The error message has nothing to do with the code in your post. Specifically post the part of the code that emits the opening message. The (2) suggests to me that you are evaluating some array in scalar context, but it is not possible to say anything definite without seeing actual code. Show the slurp_filename function as well (why are you not using File::Slurp?)
1

In addition to the Sinan's suggestion, the timeout you are getting might point to a long running process - always an issue when run under CGI. Please look at other solutions like a Queue Manager. I use Beanstalk for these situations. But I have heard good things about Gearman and The Schwartz

I also learnt a lot about running processes that take a lot of time under CGI from this article

Comments

1

After looking at the error log and seeing the error

[Mon Nov 30 14:59:07 2009] [error] slurp_filename(
'/var/www/vhosts/mydomain.net/httpdocs /youtube/youtube.pl') / opening: (2)
No such file or directory at /usr/lib64/perl5/vendor_perl/5.8.6/
x86_64-linux-thread-multi/ModPerl/RegistryCooker.pm line 540 

I thought it had something to do with the fact that I'm passing in my XML to curl as a file instead of as a string. Here is the new command that works with the xml passed as a string instead:

@curl = ('/usr/bin/curl', '-S','-v','--location', $url, '-H',
'Content-Type:'.$content_type,'-H',"Authorization: $authorization",'-H',
"X-Gdata-Key:$gdata_key",'-H',"Content-Length:$content_length",'-H',
'GData-Version:2','--data',"$xml");

And I am still using the command below to open/call curl:

open CURL, "-|", @curl;

It now runs successfully in the browser and returns me the values I am requesting with it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.