Giter VIP home page Giter VIP logo

apnsphp's People

Contributors

aporat avatar benpackard avatar danielemaiorana avatar duccio avatar edwardmp avatar hamidrezabstn avatar integer avatar jbender avatar jetwitaussi avatar marcorocca avatar potproject avatar spacedevin avatar wadxm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

apnsphp's Issues

Please add an option for silent push

/**
 * The Push Notification Silent Message.
 */
class ApnsPHP_Message_Silent extends ApnsPHP_Message
{
    /**
     * Get the payload dictionary.
     *
     * @return @type array The payload dictionary.
     */
    protected function _getPayload()
    {
        $aPayload = parent::_getPayload();

        $aPayload['aps']['sound'] = '';
        $aPayload['aps']['content-available'] = 1;

        unset($aPayload['aps']['alert']);

        return $aPayload;
    }
}

Allow chaining of the classes' functions

We should add a return this to setters and most of the void functions.

This would allow chaining of the class functions.
Consider this example:

I'm using this library and one of my classes stores an instance of the ApnsPHP_Message class in a variable.

/**
 * This is an example class that is only written here, and which isn't a real implementation
 */
class Example {
    protected $_message;

    public __construct(){
        $this->_message = new ApnsPHP_Message();
    }

    public setMessage($message){
        $this->_message = $message;
        return $this;
    }

    public getMessage(){
        return $this->_message;
    }
    // .... Let's consider we have all functionalities here ...

    public send($recipients){
         // Now if chaining was possible we could do this:
         $this->getMessage()
             ->addRecipient($recipients[0])
             ->addRecipient($recipients[1])
             ->addRecipient($recipients[2])
             ->setText('This is an example')
             ->setBadge(1)
             ->setSound('text.mp3');
        // Well you get the idea...
        return $this;
    }
}

ApnsPHP Pushes old messages with every new message

Many times, When I send a new push message to a single user or couple of users, they will sometimes get many push-notifications with older messages sent 40 minutes ago or even hours ago, along with the new one I just sent. I'm trying to understand if I'm doing anything wrong but everything is working according to the example.

<?php
    $push = new ApnsPHP_Push(...); 
    $push->setLogger($myLogger);

    $push->setRootCertificateAuthority(...);
    $push->connect();

    foreach($deviceTokens as $deviceToken){
            $msg = new ApnsPHP_Message($deviceToken);

            $msg->setBadge(1);
            $msg->setText($myMessageStr);
            $msg->setSound();
            $msg->setCustomProperty(...); // Have two custom properties
            $msg->setExpirty(30); 

            $push->add($msg);

            $msg = null;
    }

    $push->send();
    $push->disconnect();

Is there anything I'm missing? This seems like pretty simple code and I dont really see any where I could call back old messages to be pushed again.

Add to Packagist maintainers

I submitted the project to Packagist, which made me a 'maintainer' of apns-php/apns-php, which I honestly wasn't expecting them to allow me to do. If you could sign up I'll add you as a maintainer.

Send a lot of push

Hi,
If we have thousand of push to send, is it better to :
Instanciate only one new apnsPHP_push() then foreach token add mesage

OR
to array_chunk array of token (to split like every 500 array of token) then foreach array of 500 token instanciate a new apnsPHP_Push () , add message and send ?

Activity

Hey, not trying to be a jerk here but I'm curious about activity.

  • Your Google Code repo seems to be 2 years old so might be worth deleting so people can find the newer stuff. You also seem to have a LOT of outstanding pull requests.
  • Multiple people have submitted a fork to packagist, which is a bit of a PITA as a few of them look older than yours.
  • You've not tagged any versions on Packagist so people need to install dev-master.

Would you consider looking at any of these?

If you'd like to offload this, thephpleague.com could probably find somebody to take it off your hands.

When write to apple's socket always return 0

As the title, the code on the Push.php at line 175 (int)@fwrite($this->_hSocket, $aMessage['BINARY_NOTIFICATION']) always return 0 why?

This is my response:

stdClass Object
(
    [request] => POST /hikvision/push.php HTTP/1.0
Content-Type: application/x-www-form-urlencoded
User-Agent: Drupal (+http://drupal.org/)
Host: 10.1.9.xx
Content-Length: 85

tokens=92c572ec668f0e3389eb1c81ba27ff2ade7b42e4e18330b858201aaac181b61d&message=hello
    [data] => Tue, 27 May 2014 10:07:02 +0200 ApnsPHP[4016]: INFO: Trying ssl://gateway.push.apple.com:2195...
Tue, 27 May 2014 10:07:03 +0200 ApnsPHP[4016]: INFO: Connected to ssl://gateway.push.apple.com:2195.
Tue, 27 May 2014 10:07:03 +0200 ApnsPHP[4016]: INFO: Sending messages queue, run #1: 1 message(s) left in queue.
Tue, 27 May 2014 10:07:03 +0200 ApnsPHP[4016]: STATUS: Sending message ID 1 [custom identifier: unset] (1/3): 88 bytes.
Tue, 27 May 2014 10:07:03 +0200 ApnsPHP[4016]: ERROR: Unable to send message ID 1: Internal error (0 bytes written instead of 88 bytes) (999).
Tue, 27 May 2014 10:07:03 +0200 ApnsPHP[4016]: INFO: Disconnected.
Tue, 27 May 2014 10:07:03 +0200 ApnsPHP[4016]: INFO: Trying ssl://gateway.push.apple.com:2195...
Tue, 27 May 2014 10:07:04 +0200 ApnsPHP[4016]: INFO: Connected to ssl://gateway.push.apple.com:2195.
Tue, 27 May 2014 10:07:04 +0200 ApnsPHP[4016]: INFO: Sending messages queue, run #2: 1 message(s) left in queue.
Tue, 27 May 2014 10:07:04 +0200 ApnsPHP[4016]: STATUS: Sending message ID 1 [custom identifier: unset] (2/3): 88 bytes.
Tue, 27 May 2014 10:07:04 +0200 ApnsPHP[4016]: ERROR: Unable to send message ID 1: Internal error (0 bytes written instead of 88 bytes) (999).
Tue, 27 May 2014 10:07:04 +0200 ApnsPHP[4016]: INFO: Disconnected.
Tue, 27 May 2014 10:07:04 +0200 ApnsPHP[4016]: INFO: Trying ssl://gateway.push.apple.com:2195...
Tue, 27 May 2014 10:07:05 +0200 ApnsPHP[4016]: INFO: Connected to ssl://gateway.push.apple.com:2195.
Tue, 27 May 2014 10:07:05 +0200 ApnsPHP[4016]: INFO: Sending messages queue, run #3: 1 message(s) left in queue.
Tue, 27 May 2014 10:07:05 +0200 ApnsPHP[4016]: STATUS: Sending message ID 1 [custom identifier: unset] (3/3): 88 bytes.
Tue, 27 May 2014 10:07:05 +0200 ApnsPHP[4016]: ERROR: Unable to send message ID 1: Internal error (0 bytes written instead of 88 bytes) (999).
Tue, 27 May 2014 10:07:05 +0200 ApnsPHP[4016]: INFO: Disconnected.
Tue, 27 May 2014 10:07:05 +0200 ApnsPHP[4016]: INFO: Trying ssl://gateway.push.apple.com:2195...
Tue, 27 May 2014 10:07:05 +0200 ApnsPHP[4016]: INFO: Connected to ssl://gateway.push.apple.com:2195.
Tue, 27 May 2014 10:07:05 +0200 ApnsPHP[4016]: INFO: Sending messages queue, run #4: 1 message(s) left in queue.
Tue, 27 May 2014 10:07:05 +0200 ApnsPHP[4016]: WARNING: Message ID 1 [custom identifier: unset] has 3 errors, removing from queue...
Tue, 27 May 2014 10:07:05 +0200 ApnsPHP[4016]: INFO: Disconnected.

    [protocol] => HTTP/1.1
    [status_message] => OK
    [headers] => Array
        (
            [date] => Tue, 27 May 2014 08:07:02 GMT
            [server] => Apache/2.4.4 (Win32) OpenSSL/1.0.1e PHP/5.5.3
            [x-powered-by] => PHP/5.5.3
            [content-length] => 2434
            [connection] => close
            [content-type] => text/html
        )

    [code] => 200
)

Push Notification Hebrew

I am using Apns-PHP for sending push notification to IOS devices, below is the link of open source code which I have applied.

http://code.google.com/p/apns-php

It is working fine for English text messages however, for Hebrew text message sometimes its send null as text message. To overcome with it, I have applied solution suggested by the following link.

http://stackoverflow.com/a/10936493/1928421

As per the above link I have replaced my payload function with the given method, now I some text message is coming in push message but it seems like they are formatted with UTF8.

Here is the actual Hebrew text that I am passing to Apns.

"האילנית לזון זקוק לעזרה כדי לקחת מ גבעה ל ת"

And this the dictionary which is getting created by the script.

{"aps":{"alert":"\u05d4\u05d0\u05d9\u05dc\u05e0\u05d9\u05ea \u05dc\u05d6\u05d5\u05df \u05d6\u05e7\u05d5\u05e7 \u05dc\u05e2\u05d6\u05e8\u05d4 \u05db\u05d3\u05d9 \u05dc\u05e7\u05d7\u05ea \u05de \u05d2\u05d1\u05e2\u05d4 \u05dc \u05ea"\u05d0","badge":1,"sound":"default"},"server":{"serverId":null,"name":nu‌​ll}}

on device hand for the alert key I am receiving following text only.

"\u05d4\u05d0\u05d9\u05dc\u05e0\u05d9\u05ea \u05dc\u05d6\u05d5\u05df \u05d6\u05e7\u05d5\u05e7 \u05dc\u05e2\u05d6\u05e8\u05d4 \u05db\u05d3\u05d9 "

Any comment or suggestion is highly appreciated.

Free Hosting Service for ApnsPHP

Hello, this is not really a issue, but i did not know where to post this question.
I need a free hosting service to try this, because my normal hosting service does nto support OpenSSL. Does anybody know a hosting service, where this works ?
Thanks Tim.

Calling push script works in browser, but not in code

Hi there,

I have a osx app which needs to receive push notifications.
I got everything up and running and when I browse to my script via Chrome, I receive the push notification in my app.

Now I want to call the script from my code, but nothing happens. If I add error_logs() in my script I see that everything gets executed and the error array is empty, but i don't receive any notifications.

I'm using AFNetworking to do the call, but I get a success response + my php error_logs get traced, so the script is being executed.

    NSURL *url = [NSURL URLWithString:@"http://localhost/_libraries/php/ApnsPHP/major_order_push.php"];

    NSURLRequest *request = [NSURLRequest requestWithURL:url];

    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];

    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSLog(@"[ShowConsultWC] Requested push notification");

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"[ShowConsultWC] Failed to request push notification");
    }];

    [operation start];

Anyone got an idea what the issue could be?

I logged the response string and that looks okay to me (the same as in the browser)

    2013-04-02 22:25:07.725 MajorOrder[12285:303] [ShowConsultWC] Requested push notification
    2013-04-02 22:25:07.726 MajorOrder[12285:303] [ShowConsultWC] Response Tue, 02 Apr 2013 22:25:06 +02000 ApnsPHP[11093]: INFO: Trying ssl://gateway.sandbox.push.apple.com:2195...
    Tue, 02 Apr 2013 22:25:06 +0200 ApnsPHP[11093]: INFO: Connected to ssl://gateway.sandbox.push.apple.com:2195.
    Tue, 02 Apr 2013 22:25:06 +0200 ApnsPHP[11093]: INFO: Sending messages queue, run #1: 1 message(s) left in queue.
    Tue, 02 Apr 2013 22:25:06 +0200 ApnsPHP[11093]: STATUS: Sending message ID 1 [custom identifier: anicenotif] (1/3): 109 bytes.
    Tue, 02 Apr 2013 22:25:07 +0200 ApnsPHP[11093]: INFO: Disconnected.

Thanks in advance!
Frederik

Unable to connect to 'ssl://gateway.push.apple.com:2195'

I am using the following example code in a EC2 server

PHP info:
[Sorry that I have to close my server currently]

Error shown in my page:
[Sorry that I have to close my server currently]

But just dont know why it works in my MAC BOOK AIR, but not the EC2 server.

Code: (i just hide some passphrass for security concern)

setProviderCertificatePassphrase('12345678'); // Set the Root Certificate Autority to verify the Apple remote peer $push->setRootCertificationAuthority('keyandcert.pem'); // Connect to the Apple Push Notification Service $push->connect(); // Instantiate a new Message with a single recipient $message = new ApnsPHP_Message('some token'); // Set a custom identifier. To get back this identifier use the getCustomIdentifier() method // over a ApnsPHP_Message object retrieved with the getErrors() message. $message->setCustomIdentifier("Message-Badge-3"); // Set badge icon to "3" $message->setBadge(1); // Set a simple welcome text $message->setText('test'); // Play the default sound $message->setSound(); // Set a custom property $message->setCustomProperty('acme2', array('bang', 'whiz')); // Set another custom property $message->setCustomProperty('acme3', array('bing', 'bong')); // Set the expiry value to 30 seconds $message->setExpiry(30); // Add the message to the message queue $push->add($message); // Send all messages in the message queue $push->send(); // Disconnect from the Apple Push Notification Service $push->disconnect(); // Examine the error message container $aErrorQueue = $push->getErrors(); if (!empty($aErrorQueue)) { var_dump($aErrorQueue); } ?>

Problem with sound in iOS passes

Hi,
I am testing the ApnsPHP_Push object as indicated in the example documents.
The APNS notification reaches the device, but I can't manage to hear a sound, no mater how I configure the message with setSound();
I tried:
-not calling setSound();
-calling setSound();
-calling setSound('default');
-calling setSound('chimes');
I also worked through the settings in 2 different iPhones, enabling and disabling the alternatives in the notifications settings, with no success.
Is it possible the pass needs some configuration that could be missing to enable sound notifications or, for instance, in this case, a coupon pass can not receive sound notifications?
I am using latest version of iOS 6.0.1 with an iPhone 3GS.
Thank you!

setCustomProperty allows apple reserved namespace variable

setCustomProperty() function check if property name is not APPLE_RESERVED_NAMESPACE name
if not, the property name is set trimed (class ApnsPHP_Message line 232)

So if i set setCustomProperty(' aps ', 'whatever') this will add the reserved property
You have to trim the property name in the check too, line 227 :)

Push notification not coming to the iPod device

Sir/Madam,
I have used the php script provided in the url: http://www.developers-life.com/apple-push-notification.html
All the necessary client code on iPod is done.
In the php code, I have changed the $deviceToken value to my iPod touch pushID. I have generated the ck.pem on my MAC machine exactly as mentioned in the site.
When I run the php script I get a message: Connection OKnsending message :{"aps":{"alert":"Message received from javacom"}}n
But I am not getting any notification on my iPod device.
Any help is greatly appreciated.

Cannot send 0 to clear badge

According to the APNS documentation one is able to clear the notification badge by sending 0 as the badge value, but in the ApnsPHP_Message::_getPayload() only badges greater than 0 are added to the payload.

if (isset($this->_nBadge) && $this->_nBadge > 0) {
    $aPayload[self::APPLE_RESERVED_NAMESPACE]['badge'] = (int)$this->_nBadge;
}

Is this intended for some reason, or should it be corrected to greater than -1?

PS: in the mentioned code block there is an integer cast, but ApnsPHP_Message::setBadget() throws an exception if the badge value is not an integer so this may be a little overkill.

Autoloader conflicts with expected functionality

In laravel I have often run in to issues where this autoloader doesn't fully autoload things correctly.

For instance this strange error:
PHP Fatal error: Uncaught exception 'BadMethodCallException' with message 'Method [validateBoolean] does not exist.' in /vagrant/laravel/vendor/laravel/framework/src/Illuminate/Validation/Validator.php:2225

... are hard to debug because I am not sure of the autoloader. I'm fairly certain in this case it's the autoloader because other similar functionality worked before.

It'd be nice if we used PSR-0 or PSR-4 instead or found a way to not use the autoloader if we want composer's.

config option to disable logging

I am using this in an application that needs to send back json but sometimes the output gets all over the response and the app using the json crashes.

Is there a way to disable to output of the log or redirect it to a file by config option?

length of binary payload with mbstring enabled

If mbstring is enabled and replaces strlen() by mb_strlen(), the length of the binary payload is not accurate, and does not match the number of bytes sent through the socket, resulting in an error message (77 bytes written instead of 85 bytes).

mb_strlen($binary, '8bit') is accurate but mb_strlen($binary) is not.

Invalid tokens cause random "Connection reset by peer", which prevents from finishing a sending batch

Been testing the library for quite a while and, although it's definitely the best one out there for PHP, I'm almost getting insane with some random behaviour I've noticed mixing valid and invalid tokens.

After writing all push notifications to the socket (both valid and invalid tokens mixed up), we just wait through select_stream() for any error feedback. When the error is available (which it is, since $nChangedStreams is 1), we call _updateQueue(), which calls _readErrorMessage(), which does a fread() to the socket.

Although $nChangedStreams is indeed always 1 whenever it has to be, _readErrorMessage's fread() fails once in a while, throwing away the following warning (both in UNIX and Windows environments):

Warning: fread(): SSL: Connection reset by peer in path_to_project/ApnsPHP/Push.php on line 302 

Something is getting in the way between the select_stream() check, and the following fread(), but I'm not sure anymore which end is to blame here.

As mentioned, this only happens sometimes, not always, not never. When it doesn't, everything goes well and all valid notifications end up being sent, with its proper retries, as expected. On the other hand, when it fails, the queue is emptied, since the library considers there's no error if fread() returns nothing, and so retries are lost and execution ends (having lost the remaining pending notifications).

Am I the only one to notice this behaviour? Or is it a common issue? Advice is appreciated.

Thanks for your time.

Segmentation fault: 11

When I try to execute the ApnsPHP simple example I get this:

Wed, 06 Feb 2013 11:30:28 -0800 ApnsPHP[35957]: INFO: Trying ssl://gateway.sandbox.push.apple.com:2195...
Wed, 06 Feb 2013 11:30:29 -0800 ApnsPHP[35957]: INFO: Connected to ssl://gateway.sandbox.push.apple.com:2195.
Segmentation fault: 11

It fails somewhere in

$push->add($message);

In Push.php if fails on

$sMessagePayload = $message->getPayload();

Any hints or tipps on further debugging it?

From what I figured out so far, it hangs in infinite loop. Seems like getPayload() in Message.php is invoked recursively without ever breaking the recursion.

Turn off Message

Hi every body, I can use this library very well, but I can`t Turn Off the prints.
How I use this with a XML print I have some problems. How can I turn off the prints on screen?

When cert is expired there is no error about it

Fri, 28 Dec 2012 12:04:42 +0600 ApnsPHP[10318]: INFO: Trying ssl://gateway.push.apple.com:2195...
Fri, 28 Dec 2012 12:04:42 +0600 ApnsPHP[10318]: ERROR: Unable to connect to 'ssl://gateway.push.apple.com:2195':  (0)
Fri, 28 Dec 2012 12:04:42 +0600 ApnsPHP[10318]: INFO: Retry to connect (1/3)...
Fri, 28 Dec 2012 12:04:43 +0600 ApnsPHP[10318]: INFO: Trying ssl://gateway.push.apple.com:2195...
Fri, 28 Dec 2012 12:04:43 +0600 ApnsPHP[10318]: ERROR: Unable to connect to 'ssl://gateway.push.apple.com:2195':  (0)
Fri, 28 Dec 2012 12:04:43 +0600 ApnsPHP[10318]: INFO: Retry to connect (2/3)...
Fri, 28 Dec 2012 12:04:44 +0600 ApnsPHP[10318]: INFO: Trying ssl://gateway.push.apple.com:2195...
Fri, 28 Dec 2012 12:04:45 +0600 ApnsPHP[10318]: ERROR: Unable to connect to 'ssl://gateway.push.apple.com:2195':  (0)
Fri, 28 Dec 2012 12:04:45 +0600 ApnsPHP[10318]: INFO: Retry to connect (3/3)...
Fri, 28 Dec 2012 12:04:46 +0600 ApnsPHP[10318]: INFO: Trying ssl://gateway.push.apple.com:2195...
Fri, 28 Dec 2012 12:04:46 +0600 ApnsPHP[10318]: ERROR: Unable to connect to 'ssl://gateway.push.apple.com:2195':  (0)

Fatal error: Uncaught exception 'ApnsPHP_Exception' with message 'Unable to connect to 'ssl://gateway.push.apple.com:2195':  (0)' in /home/sites/api.east-media.ru/html/classes/component/ApnsPHP/Abstract.php:398
Stack trace:
#0 /home/sites/api.east-media.ru/html/classes/component/ApnsPHP/Abstract.php(334): ApnsPHP_Abstract->_connect()

To debug these error i have removed @ on line
$this->_hSocket = @stream_socket_client

to get error description from PHP

stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed in /html/classes/component/ApnsPHP/Abstract.php at line 393

Can you please post a Warning handler when cert is expired?

Explanation of using setWriteInterval()

Hey, I think you can add fixed version of this explanation to code comments above setWriteInterval() to explain when you can set write interval to zero.

  1. How works apple push service.

If you have got pack of 5 pushes and 1-2 tokens are broken sending process should going by those steps:

1.1 send 1-5 pushes
1.2 apple return error 8 to token 1
1.3 remove token 1 from queue and send 2-5
1.4 apple return error 8 to token 2
1.5 remove token 2 from queue and send 3-5
1.6 done

  1. When you set write interval to > 10000 all works correctly
  2. When you set write interval to zero you will not return error 8, you will not remove tokens 1-2 from queue and apple will not send tokens 3-5

So if you know that all of yours tokens are correct - -you can set it to zero, owertwise you should send pushes slowly :(

Problem to send emoji

Hi everyone,

I am having problem with emoji send.

I have this kind of message:
"somebody commented on your post: Bla bla bla \ue415"

but this arrives:
"somebody commented on your post: Bla bla bla ?"

How can I fix this?

Hanging on fread() for $sErrorResponse ....

Hi, for some reason, the library hangs indefinitely on this call:

protected function _readErrorMessage()
    {
        $sErrorResponse = @fread($this->_hSocket, self::ERROR_RESPONSE_SIZE);

Not sure why, but the push notification is received successfully. The script just hangs there until it times out.

Events/Function Calls On Error, Info, Status, etc

It would be nice to be able to add an event/function call when for example a token is invalid. I'm sure that's more of what the feedback service is for but I'm sure there's more uses that could come from such functionality.

Edit: I'm seeing getError should probably be used to iterate through and apply logic, but for message for multiple recipient method there's some issues with this it seems: #57

Invalid Device Token -- 64 chars required?

In attempting to use this for a Passbook update, I am getting an "invalid device token" error.

Fatal error: Uncaught exception 'ApnsPHP_Message_Exception' with message 'Invalid device token '9275172de8d10xxx5d4d9d4afdf5eff0'' in /home/xxx/apns/ApnsPHP/Message.php:77

Looking at line 77, the regex test appears to require 64 characters ('~^[a-f0-9]{64}$~i'). The device token I got back from the device, though, is much shorter. Am I using the wrong token?

Unable to connect to 'ssl://gateway.sandbox.push.apple.com:2195'

Issue

The following error is thrown when trying to push notifications from a server:

ApnsPHP[23975]: INFO: Trying ssl://gateway.sandbox.push.apple.com:2195...
ApnsPHP[23975]: ERROR: Unable to connect to 'ssl://gateway.sandbox.push.apple.com:2195':  (0)
ApnsPHP[23975]: INFO: Retry to connect (1/3)...
ApnsPHP[23975]: INFO: Trying ssl://gateway.sandbox.push.apple.com:2195...
ApnsPHP[23975]: ERROR: Unable to connect to 'ssl://gateway.sandbox.push.apple.com:2195':  (0)
ApnsPHP[23975]: INFO: Retry to connect (2/3)...
ApnsPHP[23975]: INFO: Trying ssl://gateway.sandbox.push.apple.com:2195...
ApnsPHP[23975]: ERROR: Unable to connect to 'ssl://gateway.sandbox.push.apple.com:2195':  (0)
ApnsPHP[23975]: INFO: Retry to connect (3/3)...
ApnsPHP[23975]: INFO: Trying ssl://gateway.sandbox.push.apple.com:2195...
ApnsPHP[23975]: ERROR: Unable to connect to 'ssl://gateway.sandbox.push.apple.com:2195':  (0)
<br />
<b>Fatal error</b>:  Uncaught exception 'ApnsPHP_Exception' with message 'Unable to connect to 'ssl://gateway.sandbox.push.apple.com:2195':  (0)' in /var/www/website/public_html/apn/ApnsPHP/Abstract.php:396
Stack trace:
#0 /var/www/website/public_html/apn/ApnsPHP/Abstract.php(334): ApnsPHP_Abstract-&gt;_connect()
#1 /var/www/website/public_html/apn/push.php(40): ApnsPHP_Abstract-&gt;connect()
#2 {main}
  thrown in <b>/var/www/website/public_html/apn/ApnsPHP/Abstract.php</b> on line <b>396</b><br />

The issue occurs with the default test scripts coming with the library - e.g. sample_push_custom.php.

The same code and certificates are working properly when testing in local environment (OSX 10.8.3). This way all notifications are delivered properly.

Temporary solution

Uncommenting the following code in ApnsPHP/Abstract.php, line 382, makes error disappear and notifications being delivered properly:

'verify_peer' => isset($this->_sRootCertificationAuthorityFile),

Server setup

Ubuntu 12.10, PHP 5.4.6, OpenSSL installed and enabled.
Local machines: OSX 10.8.3 + MAMP, PHP 5.4.10.

Note:

Same issue dating from 2011 has been reported at SO as well:
http://stackoverflow.com/a/6913825/1520477


Let me know if you need any additional details about the server setup.

Thanks!

Again about emoji

Hi,

everybody,
I have a problem with emoji send from a database.
When we send a 3bytes emoji, the push notification works well,
but when we send a 4bytes emoji, the push notification dont work.

4bytes emoji arrived with "?"
Do you know what could be?

shm_put_var memory warning

Hey, guys.
I've looked through the issues and didn't find anything similar.
I'm having a problem when using the Server class.

Everything works fine for a while but after a few pushes, the allocated memory
with shm_attach() seems to fill up and any attempt to shm_put_var() gives a warning
about not having enough memory.

I looked quickly through the code and I couldn't find any spot where the messages were dealloc'ed with shm_remove_var().

Am I missing something or maybe this memory cleanup is really my responsibility instead of Apns's?

Thanks in advance,
Ricardo Pedroni

First Push sent twice

Hello,
When I send push notifications the first one is sent twice. But only if there are no other messages from the app in the notification center. If there are it works fine.

Need fixing soon.

Btw. iOS 7.0.4 and Production

getErrors With Multiple Recipients Inefficient

$push->getErrors() with $message->addRecipient($token->token);

Instead of being like
Error = [ recipients[messageData],.. ]

It would make more sense to be structured like so:

Error = [ messageData, recipients[] ]

This way the message data is not repeated for every recipient because they all share the same message data anyways.

Are connections made persistent?

As per apple's best practice guidlines:

When sending notifications, avoid opening and closing the connection with the APN 
service with each notification. Instead, keep your connection to the APN service open
 when sending messages.

I was wondering if this library keeps the connection open to apple's push servers open as long as possible? I.e. if a php script executes and sends a push notification and then 2 seconds later executes again - is it opening and closing the connection over and over or reusing the same one from execution to execution?
Looking in abstract.php I see:

    $this->_hSocket = @stream_socket_client($sURL, $nError, $sError,
$this->_nConnectTimeout, STREAM_CLIENT_CONNECT, $streamContext);

But shouldn't STREAM_CLIENT_CONNECT be STREAM_CLIENT_PERSISTENT?

Also, should I be calling

// Disconnect from the Apple Push Notification Service
$push->disconnect();

at then end of every notification if I'm constantly sending notifications?

解决ApnsPHP自动加载与其它自动加载的冲突

在ApnsPHP的Autoload.php文件中的ApnsPHP_Autoload函数中加上:

//Don't interfere with other autoloaders
if (0 !== strpos($sClassName, 'ApnsPHP_')) {
    return;
}

这样可以解决与其它自动加载的冲突。

Custom Identifier Per Recipient

Originally while looking at the push_many example I was worried that creating a new object each loop for a push that would have the same message would be very inefficient but then I found $message->addRecipient(token).

It seems though that now that the message has multiple recipients that you would need a custom identifier per recipient rather than per message, if for example you needed to get back to the token's identifier in the database.

Maybe there needs to be a recipient Class, or add a second parameter which takes a unique identifier.

ApnsPHP too fast for apns

Hi,

I guess these issue (http://code.google.com/p/apns-php/issues/detail?id=8) isn't solved and gave me some headache. First i thought its related to ApnsPHP missing Errorcode 255 (error unknown) in Push.php, resulting in not being able to decifer the errormessage from apns, but adding the code didn't solve the connection losses.

The problem seems to be, that ApnsPHP is sending the messages to apns too fast, causing the apns-server-instance to die (IDK what happens), which results in the apns-server closing the connection without sending an errormessage. This results in a loss of messages, since without an errormessage containing the apropriate message-id ApnsPHP doesn't know which message was transfered successfully last and continues at the message which was SENT last, leaving the messages in between unsent (about 10 / 12 per error over here).

For me slowing down the transfer by adding some 50msecs sleep() in line 143 in Push.php solved the problem. Now it takes about 30 secs to send ~500 messages instead of ~5 secs, but at least all messages get sent. (it seems to work with 1msec, too, but since its important to ensure getting all messages transfered, i decided to stay with 50msec)

setText length error

samp_push.php
p57 $message->setText('Hello APNs-enabled device!');

when i write "$message->setText('あああああああああああああああああああかあああああああああああ?')"

then i run ".../ApnsPHP-r100/sample_push.php"

the result is "Mon, 30 Dec 2013 22:22:42 +0900 ApnsPHP[9220]: INFO: Trying ssl://gateway.sandbox.push.apple.com:2195... Mon, 30 Dec 2013 22:22:43 +0900 ApnsPHP[9220]: INFO: Connected to ssl://gateway.sandbox.push.apple.com:2195."

and my test iphone can't get the push message;

but when i write "$message->setText('あああああああああああああああああああか')"

then i run ".../ApnsPHP-r100/sample_push.php"

the result is "Mon, 30 Dec 2013 07:25:31 +0100 ApnsPHP[6298]: INFO: Trying ssl://gateway.sandbox.push.apple.com:2195... Mon, 30 Dec 2013 07:25:33 +0100 ApnsPHP[6298]: INFO: Connected to ssl://gateway.sandbox.push.apple.com:2195. Mon, 30 Dec 2013 07:25:33 +0100 ApnsPHP[6298]: INFO: Sending messages queue, run #1: 1 message(s) left in queue. Mon, 30 Dec 2013 07:25:33 +0100 ApnsPHP[6298]: STATUS: Sending message ID 1 custom identifier: Message-Badge-3: 167 bytes. Mon, 30 Dec 2013 07:25:34 +0100 ApnsPHP[6298]: INFO: Disconnected."

and my test iphone gets the push message.

i think the different result's reason is the message's length
and i don't know how to resolve it.

help me ,thanks very much!

APNs Timeout not handled correctly ?

Hi,

I've been searching for a long time with no success.
The problem :

  • APNs works correctly while there is jobs to process.
  • when a bad token or another problem occurs, APNs reconnects automatically
  • during the night, after two hours of inactivity, APNs acts like everything works but no notification is actually received by the phone.

I've read some similar problems on the newsgroup but with no solution.
Any help would be really welcomed :)

Apns issue with the server.

Hi,

I am Apns for sending push notification , it is working with my dev server.
Here is the url.

http://website-center.co.il/projects/mobileapps/test1.php
similar code i have applied on stage server here is the url.

http://www.7eyetechnologies.com/mobileapps/test1.php

on stage I am getting connection timeout error.
And here is the link of production server for the script

http://www.amigos-groups.com/mobileapps/test1.php

for it I am getting
Failed to connect: 111 Connection refused

Can you please suggest what could be the possible issue.

Thanks
Himanshu Ingole

I have 30000 devices, with the sample_push_many.php push, to 20000 when the program stops, advice

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

$query = mysql_query("select id,content from app_notifications where status=0 order by createTime desc limit 1");
list($nid,$content) = mysql_fetch_row($query);
if(empty($content)){
die();
}else{

// Connect to the Apple Push Notification Service
$t1 = microtime(true);

$alldts = array();

$query2 = mysql_query("select deviceToken from app_deviceTokens where appId='5' and id>1 order by id desc");
while($row = mysql_fetch_assoc($query2)) {
$alldts[] = $row['deviceToken'];
}
$tknum = count($alldts)+5000;

for($i=5000;$i<$tknum;$i=$i+5000){
    $dts = array();
    $small = $i-5000;
    $query2 = mysql_query("select deviceToken from app_deviceTokens where appId='5' and id<$i and id>$small order by id desc");
    while($row = mysql_fetch_assoc($query2)) {
        $dts[] = $row['deviceToken'];
    }
    echo $i.'<br>';

    // Instanciate a new ApnsPHP_Push object
    $push = new ApnsPHP_Push(
        ApnsPHP_Abstract::ENVIRONMENT_PRODUCTION,
        'com.chinadaily.ChinaDaily_production.pem'
    );

    $push->setWriteInterval(0);

    $push->connect();

    foreach($dts as $key=>$deviceToken){
        // Instantiate a new Message with a single recipient
        $message = new ApnsPHP_Message($deviceToken);

        // Set a custom identifier. To get back this identifier use the getCustomIdentifier() method
        // over a ApnsPHP_Message object retrieved with the getErrors() message.
        $message->setCustomIdentifier(sprintf("Message-Badge-%03d", $key));

        // Set badge icon to "3"
        $message->setBadge($key);
        $message->setText($content);
        // Add the message to the message queue
        $push->add($message);
    }

    // Send all messages in the message queue
    $push->send();
    $push->disconnect();
}
$timestamp = time();
mysql_query("update app_notifications set pushTime='$timestamp',status=1 where id='$nid'");

}

****_LOG_
Wed, 15 May 2013 08:26:20 +0800 ApnsPHP[32688]: INFO: Disconnected.
Wed, 15 May 2013 08:26:20 +0800 ApnsPHP[32688]: INFO: Trying ssl://gateway.sandbox.push.apple.com:2195...
Wed, 15 May 2013 08:26:21 +0800 ApnsPHP[32688]: INFO: Connected to ssl://gateway.sandbox.push.apple.com:2195.
Wed, 15 May 2013 08:26:21 +0800 ApnsPHP[32688]: WARNING: Message ID 5841 [custom identifier: Message-Badge-5840] has 1 errors, removing from queue...
Wed, 15 May 2013 08:26:21 +0800 ApnsPHP[32688]: ERROR: Unable to send message ID 5940: Internal error (0 bytes written instead of 115 bytes) (999).
Wed, 15 May 2013 08:26:21 +0800 ApnsPHP[32688]: INFO: Disconnected.
Wed, 15 May 2013 08:26:21 +0800 ApnsPHP[32688]: INFO: Trying ssl://gateway.sandbox.push.apple.com:2195...
Wed, 15 May 2013 08:26:22 +0800 ApnsPHP[32688]: INFO: Connected to ssl://gateway.sandbox.push.apple.com:2195.
Wed, 15 May 2013 08:26:22 +0800 ApnsPHP[32688]: WARNING: Message ID 5940 [custom identifier: Message-Badge-5939] has 1 errors, removing from queue...
Wed, 15 May 2013 08:26:23 +0800 ApnsPHP[32688]: INFO: Disconnected.
18000ssssssssssssssssss
Wed, 15 May 2013 08:26:24 +0800 ApnsPHP[32688]: INFO: Trying ssl://gateway.sandbox.push.apple.com:2195...
Wed, 15 May 2013 08:26:24 +0800 ApnsPHP[32688]: INFO: Connected to ssl://gateway.sandbox.push.apple.com:2195.

it is stopped......

Did not receive error codes from APNS

Hi,

I've simulated an error, eg: sending an invalid device token in the payload but didn't get error code 8 from APNS instead, no errors were surfaced.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.