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,
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".
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.
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.
It would most likely process them sequentially (why not just test it). But you can also do this:
make a file called curlrequests.sh
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
save the file and make it executable with chmod
:
chmod +x curlrequests.sh
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With