Hello to all masters of their craft. I wrote a website, like live, yes rejoice, but there is one problem with requests to the api of another site, but it is the number of requests per minute = 25 . Each site user makes from 1 to 100 requests to this api ( For example: http://api.test.ru/status/?status=get ), if there are 100 users, then 100 * 100 = 10000/60 = 167 minutes, in order to process everyone, I ask for help how you can solve this problem using PROXY, or for example, so that these requests are automatically processed, but at an event, for example? getapi, they stopped processing in turn and gave priority to exactly who caused the event. Here is my code:

$stmtproxy = $pdo->prepare('SELECT * FROM proxy'); $stmtproxy -> execute(); $rowproxy = $stmtproxy -> fetchAll(); $request = 50; //тестовое количество запросов (определяется в другом скрипте) $proxycount=ceil($request/20); for($i=0;$i<$proxycount;$i++){ $proxy=$rowproxy[$i]['ip'].':'.$rowproxy[$i]['port']; $prarr=array('http' => array('proxy'=>'tcp://'.$proxy,'request_fulluri'=>true)); $prstr=stream_context_create($prarr); for($j=0;$j<25;$j++){ // тут 25 - это максимальное число запросов $rand = '1231'; //пример запроса (каждый запрос число меняется) $myrequest = json_decode(file_get_contents ('http://api.test.ru/'.$rand.'/status/?status=get',false,$prstr),true); if($myitrade!=FALSE){ // если пускает - TRUE, если нет FALSE echo $i.' TRUE<br>'; }else {echo $i.' FALSE<br>';} } } 

The problem with this code is a long response (Just because of the proxy, although I chose the fastest), 2 is the instability of the results (for example, TTTTFFTTTFFFFTTTTTT, and if you make a query not through PROXY, then 25T, and then FALSE). To get the list and the number of requests, I use a separate command ( for example? Request ).

  • Do you have all requests different to third-party api? - Visman
  • @Visman - Yes, I make a request to this api 1 time? Request, for example, I get requests and their number, then I enter this number in the script above to make a cycle, and in a cycle I already pull out these requests one by one by changing the number of $ rand - 100ROZH
  • 3
    No need to delete the question and publish the same again. - Nick Volynkin 2:53 pm

0