簡體   English   中英

如何限制每秒卷曲的數量php

[英]how to limit number of curls per second php

我想在服務器上運行電報機器人。 我用php創建了它,它使用curl將請求發送到電報服務器。 bot電報服務器每秒可阻止30個以上的請求,這意味着我應該每秒最多發送30個帶有curl的請求。 如何將每秒的卷曲次數限制為30?

您可以在PHP中使用microtime函數來准確地測量時間! 例如:

$uT = microtime(true);
$c = 0;
while($condition)
{
    # do curl, ... here
    if(++$c>29)
    {
        if( microtime(true) - $uT < 1)
            usleep(1E6*(1-microtime(true)+$uT));
        $uT = microtime(true);
        $c = 0;
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM