如何运行顺序处理的多个curl请求? [英] How can I run multiple curl requests processed sequentially?

查看:212
本文介绍了如何运行顺序处理的多个curl请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我是一个大的unix新秀:



  • 我每15分钟通过cron运行一次curl请求。



  • 卷曲基本上用于加载具有某些参数的网页(PHP),其作用类似于以下脚本:

     卷曲http://example.com/?update_=1 




我想要实现的是运行另一个 script脚本。使用这种卷曲技术,



  • 每次运行另一个脚本

  • 在运行另一个脚本之前


我已经阅读到curl在一个命令中接受多个URL,但是我不确定这会顺序还是并行处理ulrs。

解决方案

它很可能会按顺序处理它们(为什么不只是对其进行测试)。但是您也可以这样做:


  1. 创建一个名为 curlrequests.sh 的文件p>


  2. 按如下所示将其放入文件中:

      curl http ://example.com/?update_ = 1 
    卷曲http://example.com/?update_=3
    卷曲http://example.com/?update_=234
    卷曲http://example.com/?update_=65



  3. 保存文件并使用 chmod 使其可执行:

      chmod + x curlrequests.sh 



  4. 运行文件:

      ./ curlrequests.sh 



  /path/to/file/curlrequests.sh 

作为旁注,您可以使用& 链接请求,如下所示:

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

然后使用&并行执行;

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


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 ulrs sequentially or in "parallel".

解决方案

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

这篇关于如何运行顺序处理的多个curl请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆