Exemplo n.º 1
0
 public function daemon()
 {
     $c = 0;
     $time0 = microtime(1);
     $providers = $this->proxy->config->getAllProviders();
     do {
         $val = $this->proxy->q->pop();
         if (!isset($val['provider'])) {
             usleep(100000);
             continue;
         }
         if (!isset($providers[$val['provider']])) {
             $this->proxy->log(LOG_INFO, ' [SIMPLE] config for ' . $val['provider'] . ' not found.', $val);
             continue;
         }
         $retry = 0;
         RETRY:
         $apnsobj = new spSimpleAPNS($providers[$val['provider']]['cert_path'], $providers[$val['provider']]['cert_pass'], $providers[$val['provider']]['dev_mode']);
         $apnsobj->setOption(spSimpleAPNS::OPT_BLOCKING_MODE, $this->config['non_blocking']);
         $apnsobj->setOption(spSimpleAPNS::OPT_CONNECT_ASYNC, 1);
         $apnsobj->setOption(spSimpleAPNS::OPT_CONNECT_PERSISTENT, 0);
         $connection = null;
         $msgobj = new spAPNSMessage($val['message']);
         try {
             $ret = $apnsobj->pushOne($msgobj, $val['token'], $val['identifier'], $val['expiry'], $connection);
         } catch (Exception $e) {
             $this->proxy->log(LOG_EMERG, '[SIMPLE] Exception: Code=' . $e->getCode() . ' Message=' . $e->getMessage() . " Provider=" . $val['provider'], array());
             # make ret looks like true
             $ret = 'ERROR';
         }
         $this->proxy->log(LOG_INFO, '[SIMPLE] PUSH: PROVIDER=' . $val['provider'] . ' TOKEN=' . $val['token'] . ' IDENTIFIER=' . $val['identifier'] . ' EXPIRE=' . $val['expiry'] . ' MSG=' . $msgobj->build() . ' RET=' . $ret . ' RETRY=' . $retry, array());
         # unset
         unset($apnsobj);
         # retry
         ++$retry;
         if ($ret === false && $retry <= 3) {
             goto RETRY;
         }
     } while ($this->config['run_as_daemon'] || $c++ < $this->config['loop_limit'] && microtime(1) - $time0 <= $this->config['time_limit']);
 }
Exemplo n.º 2
0
Arquivo: test.php Projeto: w3yyb/apns
<?php

require __DIR__ . '/../class/apns.inc.php';
$ao1 = new spSimpleAPNS(__DIR__ . '/apple.apns.1.pem');
$ao2 = new spSimpleAPNS(__DIR__ . '/apple.apns.2.pem');
$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$msg1 = new spAPNSMessage(array('aps' => array('alert' => array('body' => 'test1=123'))));
$msg2 = new spAPNSMessage(array('aps' => array('alert' => array('body' => 'test2-234'))));
$i = 0;
$t = microtime(1);
do {
    $ret = $ao1->push($msg1, $token);
    var_dump($ret);
    echo microtime(1) - $t, "\n";
    $ret = $ao2->push($msg2, $token);
    var_dump($ret);
    echo microtime(1) - $t, "\n";
} while (++$i < 3);