2014-02-06 21 views
0

我正在使用Parse向我的iOS應用用戶發送推送通知。這很好,但是我構建它的方式會在向多個用戶發送推送時導致頁面超時。發送多個設備令牌通過CURL解析

以下代碼位於一個while循環中,該循環通過curl一次發送一個設備令牌的數據。我將如何重建有效載荷,以便我可以推送一個包含所有設備令牌等的JSON數組......任何想法?

我While循環:

$target_device = $row['device_token']; 

$push_payload = json_encode(array(
     "where" => array(
       "deviceToken" => $target_device, 
     ), 
     "data" => array(
       "alert" => "$message" 
     ) 
)); 

$rest = curl_init(); 
curl_setopt($rest,CURLOPT_URL,$url); 
curl_setopt($rest,CURLOPT_PORT,443); 
curl_setopt($rest,CURLOPT_POST,1); 
curl_setopt($rest,CURLOPT_POSTFIELDS,$push_payload); 
curl_setopt($rest,CURLOPT_HTTPHEADER, 
     array("X-Parse-Application-Id: " . $appId, 
       "X-Parse-REST-API-Key: " . $restKey, 
       "Content-Type: application/json")); 

$response = curl_exec($rest); 

回答

0

使用set_time_limit(0);,使您的頁面沒有得到超時。

您也嘗試使用curl_milti進行並行捲曲請求。但如果請求太多,它不會幫助你避免超時。