1

I have this methode :

    $oAndroidService = new GoogleGNCService($message);
    # divide per batch with 1000 users
    $a_batch = array_chunk($a_users, 1000);
    for($i = 0; $i < count($a_batch); $i++){
        # get the liste of tokens
        foreach($a_batch[$i] as $batch){
            $a_tokens[] = $batch['token'];
        }
        # if push sent with success
        if($oAndroidService->sendPush($a_tokens)){
            foreach($a_batch[$i] as $userToProcess){
                 // update push token history
                }
            }
            echo 'PUSH SENT !';
            # unset the array with tokens
            unset($a_tokens);
        }else{
            echo 'ERROR SENT PUSH'
        }
    }

And the method that sent pushes :

public function sendPush($a_token){
    # init the curl connection
    $ch = curl_init();
    # if success connection
    if($ch){
        # array that will be send in post with curl call
        $a_post = array(
            'registration_ids'  => $a_token,
            'data'              => $this->getMessage(),
        );
        # set the options of curl request
        curl_setopt($ch, CURLOPT_URL, self::ANDROID_URL);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $this->getHeaders());
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($a_post));
        # execute the request
        $result = curl_exec($ch);
        if($result === false){
            echo('Curl failed :  ' . curl_error($ch));
            return false;
        }
        # close the request
        curl_close($ch);
        return true;
    }
    echo 'Connection failed';
    return false;
}

I have 2 questions :

  1. If I sent 1000 tokens and curl failed, I need to resend this array with tokens one more time ? If failed the second time, I need to resent third time ?
  2. If curl failed how to know what are the token that poses problems ?

Thx for you help in advance

user7424312
  • 137
  • 3
  • 10

0 Answers0