mrth2 / apns-php

Automatically exported from code.google.com/p/apns-php
0 stars 0 forks source link

Server doesn't end task #25

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
I use the code seen below to create a server. If I run this in a browser, the 
page constantly loads and doesn't ever seem to end, even though the 
notifications have been sent and received. 

Any idea why the server just keeps running? I assume this isn't normal. And, 
no, the line "if ($i <= count($notifications)) {" isn't causing an infinite 
loop, I checked. Thanks!

My code assuming $notifications is declared as a variable:

// Adjust to your timezone
date_default_timezone_set('America/New_York');

// Report all PHP errors
error_reporting(-1);

// Using Autoload all classes are loaded on-demand
require_once 'ApnsPHP/Autoload.php';

// Instanciate a new ApnsPHP_Push object
$server = new ApnsPHP_Push_Server(
    ApnsPHP_Abstract::ENVIRONMENT_SANDBOX,
    'server_certificates_bundle_sandbox.pem'
);

// Set the Root Certificate Autority to verify the Apple remote peer
$server->setRootCertificationAuthority('entrust_2048_ca.pem');

// Set the number of concurrent processes
$server->setProcesses(3);

// Starts the server forking the new processes
$server->start();

// Main loop...
$i = 1;
while ($server->run()) {

    // Check the error queue
    $aErrorQueue = $server->getErrors();
    if (!empty($aErrorQueue)) {
        // Do somethings with this error messages...
        var_dump($aErrorQueue);
    }

    // Send 10 messages
    if ($i <= count($notifications)) {
        // Instantiate a new Message with a single recipient

        $message = new ApnsPHP_Message($notifications[$i-1]['device']);

        // Set badge icon to "i"
        $message->setBadge(intval($notifications[$i-1]['badge']));
        $message->setText($notifications[$i-1]['message'].$i);

        // Add the message to the message queue
        $server->add($message);

        $i++;

    }

    // Sleep a little...
        usleep(200000);
}

Original issue reported on code.google.com by hinsdale...@gmail.com on 16 Apr 2012 at 4:03

GoogleCodeExporter commented 8 years ago
Dear,

The project source code has moved to github; if your issue is still valid, 
please open it on github page https://github.com/duccio/ApnsPHP/issues

Thanks.

Original comment by aldo.arm...@gmail.com on 26 Oct 2012 at 11:46