Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I run multiple curl requests processed sequentially?

Tags:

curl

request

Assuming I'm a big Unix rookie:

  • I'm running a curl request through cron every 15 minutes.

  • Curl basically is used to load a web page (PHP) that given some arguments, acts as a script like:

    curl http://example.com/?update_=1 

What I would like to achieve is to run another "script" using this curl technique,

  • every time the other script is run
  • before the other script is run

I have read that curl accepts multiple URLs in one command, but I'm unsure if this would process the URLs sequentially or in "parallel".

like image 790
Riccardo Avatar asked Jun 24 '10 13:06

Riccardo


People also ask

How do I run multiple curl requests in parallel?

The solution to this is to use the xargs command as shown alongside the curl command. The -P flag denotes the number of requests in parallel. The section <(printf '%s\n' {1.. 10}) prints out the numbers 1 – 10 and causes the curl command to run 10 times with 5 requests running in parallel.

How do you do multiple curl requests?

By default, you can run only 1 cURL command at a time. We will use xargs command to make multiple cURL requests in parallel. xargs command accepts one or more strings as argument, from standard input, and generates separate command for each string.


1 Answers

It would most likely process them sequentially (why not just test it). But you can also do this:

  1. make a file called curlrequests.sh

  2. put it in a file like thus:

    curl http://example.com/?update_=1 curl http://example.com/?update_=3 curl http://example.com/?update_=234 curl http://example.com/?update_=65 
  3. save the file and make it executable with chmod:

    chmod +x curlrequests.sh 
  4. run your file:

    ./curlrequests.sh 

or

   /path/to/file/curlrequests.sh 

As a side note, you can chain requests with &&, like this:

   curl http://example.com/?update_=1 && curl http://example.com/?update_=2 && curl http://example.com?update_=3` 

And execute in parallel using &:

   curl http://example.com/?update_=1 & curl http://example.com/?update_=2 & curl http://example.com/?update_=3 
like image 65
Timothy Baldridge Avatar answered Oct 08 '22 04:10

Timothy Baldridge