/** * Create new instance from options * * @param NotificationInterface $notification * @param array $options * * @return Redis */ public static function create(NotificationInterface $notification, array $options = array()) { $options += array('host' => '127.0.0.1', 'port' => 6379, 'timeout' => 0.0, 'list_key' => 'apn.push.queue', 'sleep_timeout' => 250000); $redis = new \Redis(); $redis->connect($options['host'], $options['port'], $options['timeout']); $adapter = new RedisAdapter(); $adapter->setSleepTimeout($options['sleep_timeout'])->setListKey($options['list_key'])->setRedis($redis); return new static($adapter, $notification); }
<?php include_once __DIR__ . '/../autoload.php'; if (!class_exists('Redis')) { \Demo::error('Please install PHP Redis Extension for run this demo (Redis Queue).'); } use Apple\ApnPush\Notification\Notification; use Apple\ApnPush\Notification\Connection; use Apple\ApnPush\Queue\Redis; // Create connection $connection = new Connection(CERTIFICATE_FILE, PASS_PHRASE, SANDBOX_MODE); // Create notification $notification = new Notification($connection); // Create amqp queue $amqp = Redis::create($notification); $amqp->runReceiver();
<?php include_once __DIR__ . '/../autoload.php'; if (!class_exists('Redis')) { \Demo::error('Please install PHP Redis Extension for run this demo (Redis Queue).'); } use Apple\ApnPush\Notification\Notification; use Apple\ApnPush\Notification\Message; use Apple\ApnPush\Notification\Connection; use Apple\ApnPush\Queue\Redis; // Create connection $connection = new Connection(CERTIFICATE_FILE, PASS_PHRASE, SANDBOX_MODE); // Create notification $notification = new Notification($connection); // Create message $message = new Message(); $message->setBody('[Redis queue] Hello world')->setDeviceToken(DEVICE_TOKEN); // Create redis queue $queue = Redis::create($notification); $queue->addMessage($message);