douxiao0400 2017-08-03 19:52
浏览 30
已采纳

PHP杀死正在进行的多卷曲请求

Is it possible to kill/stop multi curl requests if one of the requests receives the status code 429?

I've been trying to find a solution to this as I pull data from an API and need to avoid going over the rate limit.

These requests are asynchronous so I'm unsure how I would do this.

  • 写回答

1条回答 默认 最新

  • duanran8648 2017-08-03 20:12
    关注

    well, you should be able to cancel them at will with a CURLOPT_PROGRESSFUNCTION, have a global variable for wether or not to cancel transfers, a function that import it (with the global $var syntax), and make it return 1 when its time to cancel, eg $abort=false;ecurl_setopt($ch,CURLOPT_PROGRESSFUNCTION,function($a,$b,$c,$d,$e){global $abort;return (int)!$abort;}); - then just make $abort=true; when its time to abort them. that said, you can use CURLOPT_MAX_RECV_SPEED_LARGE to limit the speed of the transfers, if its a speed rate limit you're exceeding

    edit: note that you also need to set CURLOPT_NOPROGRESS to false for CURLOPT_PROGRESSFUNCTION to be called at all.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里