4

Web サービスを使用して、何百もの http 投稿を送信しています。ただし、このサービスでは 1 秒あたり 5 回しか許可されません。usleep コマンドがこれを行うための最良の方法であるかどうか疑問に思っています。例えば:

foreach($JSONarray['DATABASE'] as $E) 
{
    $aws = curl_init();
    //curl stuff
    curl_exec($aws);
    curl_close($aws);
    usleep(200000);
}
4

1 に答える 1

2

現在、これはテストされていませんが、私が何をするかについてのアイデアを提供する必要があります(おそらく、このスニペットはそのまま機能します-誰にもわかりません...):

// presets
$thissecond = time();
$cnt = 0;

foreach($JSONarray['DATABASE'] as $E) 
{
  while ($thissecond == time() && $cnt > 4) { // go into "waiting" when we going to fast
    usleep(100000); // wait .1 second and ask again
  }

  if ($thissecond != time()) { // remember to reset this second and the cnt
    $thissecond = time();
    $cnt = 0;
  }

  // off with the payload
  $aws = curl_init();
  //curl stuf
  curl_exec($aws);
  curl_close($aws);

  // remember to count it all
  $cnt++;
}
于 2011-08-20T10:27:59.943 に答える