Permanent connection through PHP with APNS

I know that there are many posts on SO that solve this problem, unfortunately, I am not so advanced in PHP programming, and I have a question that I haven’t answered anywhere:

Many of the tutorials for Apple Push Notifications create a connection through stream_socket_client (). But most of them lack the flag "STREAM_CLIENT_PERSISTENT". Will this flag really keep in touch? If so, when will it be closed? The documentation says that it will remain connected also when the page reloads. Does it depend on the sessions?

The version without this flag works, but I'm afraid that APNS will block me as soon as I put the production certificates, etc. (described here ). Thanks in advance.

+5
source share
1 answer

According to PHP documentation for predefined constants, using STREAM_CLIENT_PERSISTENT with an APNS connection should support an active connection between page loads. This is a requirement for an APNS connection because it WILL throttles you because it considers any disconnection after sending a payload a potential denial of service attack.

- , , , , APNS- PHP. PHPXMLRPC, .

<?php

include '../vendors/xmlrpc.inc';

$hostName = 'localhost'; # Your services endpoint here.
$rpcPath = '';
$port = 7077;

if($_GET['action'] == 'provisioning')
{
    $echoString = new xmlrpcmsg(
        'provision',
        array(
            php_xmlrpc_encode('appid'),
            php_xmlrpc_encode('/path/to/certificate.pem'),
            php_xmlrpc_encode('sandbox'),
            php_xmlrpc_encode(100)
        )
    );
    $continue = TRUE;
}

if($_GET['action'] == 'notify')
{
    $echoString = new xmlrpcmsg(
        'notify',
        array(
            php_xmlrpc_encode('paparazzme'),
            php_xmlrpc_encode(array('6bcda...', '7c008...')),
            php_xmlrpc_encode(array(array("aps" => array("alert" => "Hello User 1" )), array("aps" => array("alert" => "Hello User 2" ))))
        )
    );
    $continue = TRUE;
}

if($continue == true)
{
    # Create a client handle and send request
    $client = new xmlrpc_client($rpcPath, $hostName, $port);

    # A little verbose debug
    $client->setDebug(2);

    # The response
    $response = &$client->send($echoString);

    # Check if response is good
    if (! $response->faultCode())
        print "\nReturned string is: " . php_xmlrpc_decode($response->value()) . "\n";
    else
        print "An error occurred: \nCode: " . $response->faultCode() . " Reason: '" . htmlspecialchars($response->faultString()) . "'\n";
}

?>

: APNS iPhone iTouch

, , - , iPhone, , , .

, Uban Airship, 250 000 APN Server , API, .

+6

All Articles