서드 파티 서버에서 한꺼번에 여러명에게 메시지를 보낼때 다음과 같은 코드를 사용했는데요.

 

function sendMessageToPhone($authCode, $deviceRegistrationId, $msgType, $messageText) { 

  $headers = array('Authorization: GoogleLogin auth=' . $authCode);        
  $data = array(            
   'registration_id' => $deviceRegistrationId,            
   'collapse_key' => $msgType,            
   'data.message' => $messageText
   //TODO Add more params with just simple data instead                  
  );        
  $ch = curl_init();         
  curl_setopt($ch, CURLOPT_URL, "https://android.apis.google.com/c2dm/send");        
  if ($headers)            
   curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);        
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);        
  curl_setopt($ch, CURLOPT_POST, true);        
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);        
  curl_setopt($ch, CURLOPT_POSTFIELDS, $data);          
  $response = curl_exec($ch);         
  curl_close($ch);         

return $response;    
 }

php 소스 입니다.

 

사용자수에 따라 for문 돌리는 상태인데 사용자수가 얼마 안되면 잘 되고 있습니다.

 

하지만 사용자수가 많아지면(천명이상)  문제가 되고 있습니다.

한사람 한사람 매번 접속하여 보내기 때문에 서버가 견디지 못하고 시간이 오래걸립니다.

 

한방에 보내거나 더 좋은 방법이 없을까요?