트위터에서 api를 스트리밍하는 짹짹을 cURL을 사용하여 명령 줄로 보내주는 php cli 스크립트를 만들었습니다. 스크립트를 시작하면 짹짹이 나오기 시작하지만 매번 50 번째 짹짹마다 다음과 같은 오류가 발생합니다. "쉬운 터보, 최근에 요청이 너무 많습니다. 차분함을 높입니다."헤더가 없으며 다른 출력도 없습니다.PHP 다중 연결을 방해하는 방법
나는 너무 많은 연결을 만들 것이라고 가정하지만, 일단 cURL 만 초기화하면됩니다.
//initialize cURL connection
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://stream.twitter.com/1.1/statuses/filter.json? follow=34572451,27260086');
curl_setopt($ch, CURLOPT_USERPWD, 'USERNAME:PASSWORD');
curl_setopt($ch, CURLOPT_WRITEFUNCTION, 'saveTweet');
curl_setopt($ch, CURLOPT_MAXCONNECTS, 1);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_FORBID_REUSE, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Cache-Control: max-age=0', 'Connection: keep-alive', 'Keep-Alive: 3600'));
//then loop the execution to retrieve tweets
while(1){
echo $i++.'->'; //echo number, so we know it stops at 50
try {
//calls saveTweet() as callback, which only purpose is to output the tweet
curl_exec($ch);
}
catch(Exception $e) {
//echo error described above
echo $e->getMessage();
break;
}
}
이 어떻게 (이 것을 않는 경우, 정말 정확한 문제를 모르는) 너무 많은 요청을에서 컬을 방지 않습니다 여기 내 코드는? 또는 위의 오류를 방지하려면 어떻게합니까? 한 번 한 동안 sleep 및 usleep 필요 그렇게
DOS; TPS를 낮추십시오. – SparKot
TPS는 무엇을 의미합니까? 나는 while 루프에서 잠을 자려고했는데 (1 ~ 30 초), 작동하지 않았다. –