Giter VIP home page Giter VIP logo

pushok's Introduction

Pushok

PHP >= 8.1 Build Status Latest Version on Packagist Total Downloads Coverage Status Quality Score Software License StandWithUkraine

Do you like the library? Please consider donating to support Ukraine ๐Ÿ‡บ๐Ÿ‡ฆ

Pushok is a simple PHP library for sending push notifications to APNs.

Features

  • Uses new Apple APNs HTTP/2 connection
  • Supports JWT-based authentication
  • Supports Certificate-based authentication
  • Supports new iOS 10 features such as Collapse IDs, Subtitles and Mutable Notifications
  • Uses concurrent requests to APNs
  • Tested and working in APNs production environment

Requirements

  • PHP >= 8.1
  • lib-curl >= 7.46.0 (with http/2 support enabled)
  • lib-openssl >= 1.0.2e

Docker image that meets requirements can be found here. Or you can follow this tutorial to create your own docker image with curl with HTTP/2 support.

Install

Via Composer

$ composer require edamov/pushok

Getting Started

Using JWT token. See Handling Notification Responses from APNs for more info.

<?php
require __DIR__ . '/vendor/autoload.php';

use Pushok\AuthProvider;
use Pushok\Client;
use Pushok\Notification;
use Pushok\Payload;
use Pushok\Payload\Alert;

$options = [
    'key_id' => 'AAAABBBBCC', // The Key ID obtained from Apple developer account
    'team_id' => 'DDDDEEEEFF', // The Team ID obtained from Apple developer account
    'app_bundle_id' => 'com.app.Test', // The bundle ID for app obtained from Apple developer account
    'private_key_path' => __DIR__ . '/private_key.p8', // Path to private key
    'private_key_secret' => null // Private key secret
];

// Be aware of thing that Token will stale after one hour, so you should generate it again.
// Can be useful when trying to send pushes during long-running tasks
$authProvider = AuthProvider\Token::create($options);

$alert = Alert::create()->setTitle('Hello!');
$alert = $alert->setBody('First push notification');

$payload = Payload::create()->setAlert($alert);

//set notification sound to default
$payload->setSound('default');

//add custom value to your notification, needs to be customized
$payload->setCustomValue('key', 'value');

$deviceTokens = ['<device_token_1>', '<device_token_2>', '<device_token_3>'];

$notifications = [];
foreach ($deviceTokens as $deviceToken) {
    $notifications[] = new Notification($payload,$deviceToken);
}

// If you have issues with ssl-verification, you can temporarily disable it. Please see attached note.
// Disable ssl verification
// $client = new Client($authProvider, $production = false, [CURLOPT_SSL_VERIFYPEER=>false] );
$client = new Client($authProvider, $production = false);
$client->addNotifications($notifications);



$responses = $client->push(); // returns an array of ApnsResponseInterface (one Response per Notification)

foreach ($responses as $response) {
    // The device token
    $response->getDeviceToken();
    // A canonical UUID that is the unique ID for the notification. E.g. 123e4567-e89b-12d3-a456-4266554400a0
    $response->getApnsId();
    
    // Status code. E.g. 200 (Success), 410 (The device token is no longer active for the topic.)
    $response->getStatusCode();
    // E.g. The device token is no longer active for the topic.
    $response->getReasonPhrase();
    // E.g. Unregistered
    $response->getErrorReason();
    // E.g. The device token is inactive for the specified topic.
    $response->getErrorDescription();
    $response->get410Timestamp();
}

Using Certificate (.pem). Only the initilization differs from JWT code (above). Remember to include the rest of the code by yourself.

<?php

$options = [
    'app_bundle_id' => 'com.app.Test', // The bundle ID for app obtained from Apple developer account
    'certificate_path' => __DIR__ . '/private_key.pem', // Path to private key
    'certificate_secret' => null // Private key secret
];

$authProvider = AuthProvider\Certificate::create($options);

...

Note : Please see this post about ssl verification

Options to fiddle around. See Sending Notification Requests to APNs

<?php

$client = new Client($authProvider, $production = false);
$client->addNotifications($notifications);


// Set the number of concurrent requests sent through the multiplexed connections. Default : 20
$client->setNbConcurrentRequests( 40 );

// Set the number of maximum concurrent connections established to the APNS servers. Default : 1
$client->setMaxConcurrentConnections( 5 );


$responses = $client->push();

Testing

$ composer test

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

pushok's People

Contributors

ahfeel avatar akulik avatar allphat avatar angvp-sng avatar bandess avatar crewsycrews avatar dean151 avatar edamov avatar edwardmp avatar fogush avatar hstrowd avatar jolamar avatar jredoules avatar knyjoh avatar koiiiey avatar lucadegasperi avatar marcorocca avatar mkosiedowski avatar ozyab avatar peter279k avatar rasmusbe avatar remcoanker avatar sicaboy avatar soren121 avatar srjlewis avatar tobiasbambullis avatar vbartusevicius avatar wyrmling avatar xgin avatar yosus 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

pushok's Issues

"minimum-stability" should be stable, not dev

The "minimum-stability" block defined on composer.json means these all dependencies will install unstable versions.

IMHO, I suggest we can consider let "minimum-stability" be stable because it's proper for this package to install the stable versions of dependencies.

JSON_FORCE_OBJECT breaks arrays

Hello,

I noticed that the library use the json_encode JSON_FORCE_OBJECT option in the Payload toJson method. This causes non-associative array to be outputed as objects.

I'm wondering why this choice ? It makes a few of my apps crash as they were expected non-associative arrays.

Output :

  "path_list" = {
                    0 = {
                        sign = "xxxx";
                        url = "xxx";
                    }
                };

I did the fix on my end, and now have this output :

  "path_list" = [
                    {
                        sign = "xxxx";
                        url = "xxx";
                    }
               ];

To me, the library should only set this option if it was asked by the user. I can make a PR after we talk about it.

Compatible with PHP7.2 ?

It seems that the library requires spomky-labs/jose 6.1.1 which is not compatible with PHP 7.2 because it uses a custom class Object which is not allowed since PHP 7.2

Fatal error: Cannot use FG\ASN1\Object as Object because 'Object' is a special class name in ......../vendor/spomky-labs/jose/src/KeyConverter/ECKey.php on line 17

spomky-labs/jose 7.0.0 has replaced Object by ASNObject which is compatible with PHP 7.2

EDIT actually I just saw you commited it 20 days ago, so I don't understand why I'm still getting the 6.1.1 dependancy when I use php composer.phar require edamov/pushok

Sorry for the useless post.

private_key_path option not working

First of all, thanks for creating this library! I never thought it would be so complicated setting up push notifications with the new HTTP/2 protocol.
Although I have a problem with the private_key_path option. When providing __DIR__ . '/key.p8 I get the following error (I have provided the relative paths only to make it more readable):

Notice: Undefined offset: 1 in vendor/spomky-labs/jose/src/KeyConverter/KeyConverter.php on line 190

Fatal error: Uncaught Assert\InvalidArgumentException: Unable to load the key in vendor/beberlei/assert/lib/Assert/Assertion.php:285
Stack trace: #0 vendor/beberlei/assert/lib/Assert/Assertion.php(1679): Assert\Assertion::createException(true, 'Unable to load ...', 38, NULL)
#1 vendor/spomky-labs/jose/src/KeyConverter/KeyConverter.php(158): Assert\Assertion::false(true, 'Unable to load ...')
#2 vendor/spomky-labs/jose/src/KeyConverter/KeyConverter.php(119): Jose\KeyConverter\KeyConverter::loadKeyFromPEM('-\xD19\x8E\x8B\x14\x17/\xAC\xFB!"\xF4-\n...', NULL)
#3 vendor/spomky-labs/jose/src/KeyConverter/KeyConverter.php(103): Jose\KeyConverter\KeyConverter::loadFromKey('-\xD19\x8E\x8B\x14\x17/\xAC\xFB!"\xF4-\xAC...', NULL)
#4 vendor/spomky-labs/jose/src/Factory/JWKFactory.php(347): Jose\KeyConverter\KeyConverter::loadFromKeyFile('key.p8', NULL)
#5 vendor/edamov/pushok/src/AuthProvider/Token. in vendor/beberlei/assert/lib/Assert/Assertion.php on line 285

The only way to make it work is adding this code after line 152 in the file vendor/sponky-labs/jose/src/KeyConverter/KeyConverter.php:

$pem = <<<EOT
<contents of the key.p8 file>
EOT;

I'm happy for any suggestion about what might be the problem!

composer require issues

$ composer require edamov/pushok
...
  Problem 1
    - Can only install one of: edamov/pushok[0.2.3, 0.1.x-dev].
    - Can only install one of: edamov/pushok[0.1.x-dev, 0.2.3].
    - Installation request for edamov/pushok ^0.2.3 -> satisfiable by edamov/pushok[0.2.3].
    - Installation request for edamov/pushok 0.1.x-dev -> satisfiable by edamov/pushok[0.1.x-dev].

I'm not sure exactly what this means but from my searches it sounds like I'm stuck.

PHP Notice: Use of undefined constant CURL_HTTP_VERSION_2

When I run the unit test, it reports error -> PHP Notice: Use of undefined constant CURL_HTTP_VERSION_2.

I run a system with ubuntu 14.04, php7.1 curl info as below:

cURL support => enabled
cURL Information => 7.52.1
Age => 3
Features
AsynchDNS => No
CharConv => No
Debug => No
GSS-Negotiate => No
IDN => No
IPv6 => Yes
krb4 => No
Largefile => Yes
libz => Yes
NTLM => Yes
NTLMWB => Yes
SPNEGO => No
SSL => Yes
SSPI => No
TLS-SRP => Yes
HTTP2 => Yes
Protocols => dict, file, ftp, ftps, gopher, http, https, imap, imaps, ldap, ldaps, pop3, pop3s, rtmp, rtsp, smb, smbs, smtp, smtps, telnet, tftp
Host => x86_64-pc-linux-gnu
SSL Version => OpenSSL/1.0.2j
ZLib Version => 1.2.8

the cURL lib 7.52.1 is compiled on my system, so after I search the code. I found that instead of CURL_HTTP_VERSION_2 I should use constant CURL_HTTP_VERSION_2_0

curl extension obviously uses different form of that constant but not mentioned in any of the php documents.
So, make a condition check in your code will help.

Performance Question

Currently we use old apns method (with pem cert) and we can send 5000 message in a minute per server (we use aws t2.micro servers with 1 GB RAM).

Is http2 method faster than the old one ? Approximately How many pushes can you send in a minute with this library ? (I know it depends on many factors like cpu, network speed etc... But I just need an average number to understand if it's worth to try the new one)

Unable to install library edamov/pushok

I keep receiving error

  • edamov/pushok 0.6.4 requires lib-curl >=7.46.0 -> the requested linked library curl has the wrong version installed or is missing from your system, make sure to have the extension providing it.

when I run composer require edamov/pushok notwithstanding I have lib-curl at version 7.66 as seen by:

curl-config --version
libcurl 7.66.0

May you check?
Thanks.

Error in executing test script

I personalised the test script with my app information to get:

<?php
//require __DIR__ . '/vendor/autoload.php';

use Pushok\AuthProvider;
use Pushok\Client;
use Pushok\Notification;
use Pushok\Payload;
use Pushok\Payload\Alert;

$options = [
    'key_id' => '255YU6R88K', // The Key ID obtained from Apple developer account
    'team_id' => 'GF9PQ87F68', // The Team ID obtained from Apple developer account
    'app_bundle_id' => 'com.augmentedReality.virtualTags', // The bundle ID for app obtained from Apple developer account
    'private_key_path' => 'AuthKey_255YU6R88K.p8', // Path to private key
    'private_key_secret' => null // Private key secret
];

$authProvider = AuthProvider\Token::create($options);

$alert = Alert::create()->setTitle('Hello!');
$alert = $alert->setBody('First push notification');

$payload = Payload::create()->setAlert($alert);

//set notification sound to default
$payload->setSound('default');

//add custom value to your notification, needs to be customized
$payload->setCustomValue('key', 'value');

$deviceTokens = ['4303AC16C13448D4820345994E898FBD1EE95DD6B702B0133E5C065808FA8BE7'];

$notifications = [];
foreach ($deviceTokens as $deviceToken) {
    $notifications[] = new Notification($payload,$deviceToken);
}

$client = new Client($authProvider, $production = false);
$client->addNotifications($notifications);



$responses = $client->push(); // returns an array of ApnsResponseInterface (one Response per Notification)

foreach ($responses as $response) {
    $response->getApnsId();
    $response->getStatusCode();
    $response->getReasonPhrase();
    $response->getErrorReason();
    $response->getErrorDescription();
}
?>

commenting out the first line that linked nowhere, but I get error:

PHP Fatal error: Uncaught Error: Class 'Pushok\AuthProvider\Token' not found in /var/www/html/php/push/comodoPush.php:18
Stack trace:
#0 {main}
thrown in /var/www/html/php/push/comodoPush.php on line 18

lib-openssl 1.0.2j error

On CentOS 7 / PHP 7.0.14 with OpenSSL 1.0.2j installing with composer returns this error: "edamov/pushok 0.2.1 requires lib-openssl >=1.0.2.5 -> the requested linked library openssl has the wrong version installed or is missing from your system, make sure to have the extension providing it."

Can you fix it?

Keeping provider auth token

Apple says: "Do not generate a new provider authentication token for each push request that you send. After you obtain a token, continue to use it for all your push requests during the tokenโ€™s period of validity, which is one full hour."

How to get this to work with your library?

Error when sending a push notification through the Docker Library

Hey there,

First of all thank you for the library.
I've been doing some tests and because I couldn't get it to work on Amazon Linux AWS I deployed your docker machine but I still get an error.

The error is:
Undefined offset: 1 in vendor/edamov/pushok/src/Client.php on line 95

I've been checking what actually causes the error and it seems that this line:

$result = curl_multi_getcontent($handle);

returns and empty response.

My team id and certificate combination is correct.
If you can give me a heads up or any guidance how to fix this I will be more than grateful.

Thanks in advance.

PHP CLI works, PHP-FPM is not working

Hello,

everything works fine from php command line, but php-fpm is not working (same code).
I'm using the provided docker image, and I added php-fpm7 to the Dockerfile

RUN apk add --update --no-cache \
        php7 \
        php7-fpm \
        php7-curl \
        php7-dom \
        php7-gmp \
        php7-intl \
        php7-json \
        php7-mbstring \
        php7-openssl \
        php7-phar \
        php7-xml \
        php7-xmlwriter

phpinfo() shows that i have all the required libraries installed in both CLI and FPM versions:

SSL Version | OpenSSL/1.0.2o
HTTP2 | Yes
cURL Information | 7.50.1

When i send a push from CLI, it arrives properly to the device.
However when I'm trying to send it through PHP-FPM, i'm getting this error.

server_1  | 2018/05/08 21:40:58 [error] 7#7: *34 FastCGI sent in stderr: "PHP message: PHP Notice:  Undefined offset: 1 in /var/www/api/vendor/edamov/pushok/src/Client.php on line 123
server_1  | PHP message: Slim Application Error:
server_1  | Type: TypeError
server_1  | Message: Argument 3 passed to Pushok\Response::__construct() must be of the type string, null given, called in /var/www/api/vendor/edamov/pushok/src/Client.php on line 125
server_1  | File: /var/www/api/vendor/edamov/pushok/src/Response.php
server_1  | Line: 144
server_1  | Trace: #0 /var/www/api/vendor/edamov/pushok/src/Client.php(125): Pushok\Response->__construct(0, '', NULL, 'a4a16383226d5a5...')
server_1  | #1 /var/www/api/templates/sendtest.phtml(53): Pushok\Client->push()
server_1  | #2 /var/www/api/vendor/slim/php-view/src/PhpRenderer.php(188): include('/var/www/api/te...')
server_1  | #3 /var/www/api/vendor/slim/php-view/src/PhpRenderer.php(169): Slim\Views\PhpRenderer->protectedIncludeScope('/var/www/api/sr...', Array)
server_1  | #4 /var/www/api/vendor/slim/php-view/src/PhpRenderer.php(62): Slim\Views\PhpRenderer->fetch('sendtest.phtml', Array)
server_1  | #5 /var/www/api/src/routes.php(8): Slim\Views\PhpRenderer->render(Object(Slim\Http\Response), 'sendtest.phtml', Array)
server_1  | #6 [internal function]: Closure->{closure}(Object(Slim\Http\Requ" while reading response header from upstream, client: 172.23.0.1, server: , request: "GET /test2 HTTP/1.1", upstream: "fastcgi://172.23.0.3:9000", host: "localhost"

any ideas / advices?
does it works for anyone with PHP-FPM?

APNS Feedback service

Thanks for this great library. It works like a charm. I just wondered about the 410 error code.
I have sent a push notification successfully to a device and later uninstalled App, but still getting 200 response.

Please let me know how can I can get the 410 response code.

PHP Fatal error: Uncaught TypeError: Argument 3 passed to Pushok\Response::__construct() must be of the type string, null given, called in

Hi ,
I am not a php developer so please help me with following error

PHP Fatal error: Uncaught TypeError: Argument 3 passed to Pushok\Response::__construct() must be of the type string, null given, called in /Users/anargha/apnNew/vendor/edamov/pushok/src/Client.php on line 101 and defined in /Users/anargha/apnNew/vendor/edamov/pushok/src/Response.php:136
Stack trace:
#0 /Users/anargha/apnNew/vendor/edamov/pushok/src/Client.php(101): Pushok\Response->__construct(0, '', NULL)
#1 /Users/anargha/apnNew/test.php(43): Pushok\Client->push()
#2 {main}
thrown in /Users/anargha/apnNew/vendor/edamov/pushok/src/Response.php on line 136

Fatal error: Uncaught TypeError: Argument 3 passed to Pushok\Response::__construct() must be of the type string, null given, called in /Users/anargha/apnNew/vendor/edamov/pushok/src/Client.php on line 101 and defined in /Users/anargha/apnNew/vendor/edamov/pushok/src/Response.php:136
Stack trace:
#0 /Users/anargha/apnNew/vendor/edamov/pushok/src/Client.php(101): Pushok\Response->__construct(0, '', NULL)
#1 /Users/anargha/apnNew/test.php(43): Pushok\Client->push()
#2 {main}
thrown in /Users/anargha/apnNew/vendor/edamov/pushok/src/Response.php on line 136

Problem with Title-loc-args

Hi,
Thk's for your job.

I don't understand how to send title-loc-args.
I'use the method
$alert->setTitleLocArgs(

but it dosen't works.

I'm trying manually with this

$alert->setTitleLocArgs(["toto"])

But in the json request i have

string(221) "{"aps":{"alert":{"body":"Ggf","title-loc-key":"_NEW_MSG_FROM_","title-loc-args":{"0":"toto"}},"badge":1,"sound":"default"},"id":"4","prenom":"Iosca","nom":"Edouard","username":"eiosca","type":"message","notification":407}"

I think the problem is because i have the index in the json request.
Maybe i not use this method correctly?

Thk's for your help.

web-token 2?

Hi,

would you consider updating the dependency on web-token to version 2? It would mean having a min PHP version of 7.2, but according to #72 that seems to be on the agenda anyway...
I could give it a try and create a PR, if wanted.

Custom Notification Id

Is there a way to set a custom notification id (eg database record id) which i can set and refer to if i get the apns response?

Php 5 compatibility

Hello,
I haven't seen other library for send the new APNs Apple push notifications in PHP, but my server have installed PHP 5.3+, and I would like to know what part of the code fails for the compatibility of PHP 5 (for try to solve, or try to found a workaround)

Thank you very much for this library!

Silent Push Notification

Hi,

I need to send silent push notification, for which I am using the following code

$authProvider = AuthProvider\Token::create($this->options['ios']);
$alert = Alert::create()->setTitle($this->title);
$alert = $alert->setBody($this->message);
$payload = Payload::create()->setAlert($alert);
$payload->setContentAvailability(true);
$payload = $payload->setSound('default');
foreach ($this->data as $key => $value) {
    $payload = $payload->setCustomValue($key, $value);
}
$notifications = [];
foreach ($this->deviceTokens as $deviceToken) {
    $notifications[] = new Notification($payload, $deviceToken);
}
$client = new Client($authProvider, $production = false);
$client->addNotifications($notifications);
$client->push();

It sends the push notification to the device, however, the push notifications are displayed in notification center which I don't want.

How to include content-available=1 to enable and send silent push notification using this library.

Custom Value do not work

When I try send custom value but It isn't working :/

I'm doing it

$payload->setCustomValue('object', 'question')
        ->setCustomValue('id', 1);

But It doesn't get anything on client.

How do you handle the response in Swift 3 it gives?

I have this code when I get the push notification, push notifications work by the way.

// Push notification received
    func application(_ application: UIApplication, didReceiveRemoteNotification data: [AnyHashable : Any]) {
        // Print notification payload data
        print("Push notification received: \(data)")
        
        let aps = data[AnyHashable("aps")]!
        
        print(aps)
    }

Here is the console output...

Push notification received: [AnyHashable("samplekey"): samplevalue, AnyHashable("aps"): {
    alert =     {
        body = hey;
        title = "Hello!";
    };
    sound = default;
}]
{
    alert =     {
        body = hey;
        title = "Hello!";
    };
    sound = default;
}

How do I get access to the variables in the alert object in Swift3?

Fatal error: Uncaught TypeError: Argument 3 passed to Pushok\Response::__construct() must be of the type string, null given

Hello,

First, thanks for your lib.
I'm trying to use it, but I'm having some errors:

Notice: Undefined offset: 1 in ...\vendor\edamov\pushok\src\Client.php on line 95

Fatal error: Uncaught TypeError: Argument 3 passed to Pushok\Response::__construct() must be of the type string, null given, called in ...\vendor\edamov\pushok\src\Client.php on line 97 and defined in ...\vendor\edamov\pushok\src\Response.php:136 Stack trace: #0 ...\vendor\edamov\pushok\src\Client.php(97): Pushok\Response->__construct(0, '', NULL)

This happens when I'm doing $client->push();

Sometimes message not send to all the device tokens

Sometimes (5 out of 10 times) not all messages were send to all the devicetokens.

We discovered that sometimes the connection breaks in the while loop in Client.php without any reason.
After investigation we discovered adding this line solves the problem:

...
while (($execrun = curl_multi_exec($mh, $running)) == CURLM_CALL_MULTI_PERFORM);

if ($execrun != CURLM_OK) {
break;
}

//ADDED THIS AFTER CURLM_OK
if ($running && curl_multi_select($mh) === -1) {
usleep(250);
}

while ($done = curl_multi_info_read($mh)) {
...

Don't know why. But after we had made this change, we hadn't had issues anymore.
Hope this helps someone.

Curl version: 7.52.1

Alert subtitle

The Alert class has a subtitle property but when the object is serialized to json the property is not included.

Notice: Undefined Offset

Notice: Undefined offset: 1","class":"Symfony\Component\Debug\Exception\ContextErrorException","trace":[{"namespace":"","short_class":"","class":"","type":"","function":"","file":"/var/www/public_html/devsite/vendor/edamov/pushok/src/Client.php","line":95

This is what I got from my symfony debugger. Unless I disable errors for notices I can't use the library. Any idea the issue on that line?

Hangs with test connection

I am trying to use this to make a simple connection to Apple. I pass an erroneous app ID + device ID and the connection just hangs in Client.php . IP is not blocked because a simple shell curl command to either dev or prod apple servers works fine (It returns an error of course).

With the current Client.php It hangs forever in the second while here:

` $active = null;
do {
$mrc = curl_multi_exec($mh, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);

     while ($active && $mrc == CURLM_OK) {

         if (curl_multi_select($mh) != -1) {
             do {
                 $mrc = curl_multi_exec($mh, $active);
             } while ($mrc == CURLM_CALL_MULTI_PERFORM);
         }

     }

However, If I replace this with this simple loop here.
do {
$mrc = curl_multi_exec($mh, $active);
} while ($active > 0);
`

All works fine.

System is out of the box Debian instance with PHP 7.0.16-3, OpenSSL 1.1.0e , cURL 7.52.1

Any ideas ?

Client->Post() hangs up PHP script

The post() function from the Client class seems to never return anything and keeps running. I'm trying this code (not much changed from the example):

	function sendPush($deviceTokens, $title, $body, $customValues = null, $badge = 1){
		$options = [
		    'key_id' => 'xxx', // The Key ID obtained from Apple developer account
		    'team_id' => 'xxx', // The Team ID obtained from Apple developer account
		    'app_bundle_id' => 'xxx', // The bundle ID for app obtained from Apple developer account
		    'private_key_path' => 'xxx', //Path to p8 key
		    'private_key_secret' => null // Private key secret
		];

		$authProvider = AuthProvider\Token::create($options);

		$alert = Alert::create()->setTitle($title);
		$alert = $alert->setBody($body);

		$payload = Payload::create()->setAlert($alert);

		//set notification sound to default
		$payload->setSound('default');

		if(isset($customValues) && $customValues != null){
			for($i = 0; $i < count($customValues); $i++) $payload->setCustomValue($customValues[$i][0], $customValues[$i][1]);
		}
		if($badge != -1) $payload->setBadge($badge);

		$notifications = [];
		foreach ($deviceTokens as $deviceToken) {
		    $notifications[] = new Notification($payload,$deviceToken);
		}

		$client = new Client($authProvider, $production = false);
		$client->addNotifications($notifications);

		echo(1);

		$responses = $client->push(); // returns an array of ApnsResponseInterface (one Response per Notification)

		echo(2);
		
		foreach ($responses as $response) {
		    $response->getApnsId();
		    $response->getStatusCode();
		    $response->getReasonPhrase();
		    $response->getErrorReason();
		    $response->getErrorDescription();
		}
	}

As you can see, I've put two debug echoes before and after the push() function. While the 1 gets printed, the 2 doesn't. When I try to echo $responses, I get NULL, too, so it seems like it fails to get a response from the servers.

The push notification gets sent successfully though, it's just that I can't do anything after sending the push.

requires lib-curl >=7.46.0

Ubuntu 14.04 this works great. OSX 10.11.6 w/homebrew is another story:

$ composer require edamov/pushok:0.2.3
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for edamov/pushok 0.2.3 -> satisfiable by edamov/pushok[0.2.3].
    - edamov/pushok 0.2.3 requires lib-curl >=7.46.0 -> the requested linked library curl has the wrong version installed or is missing from your system, make sure to have the extension providing it.


Installation failed, reverting ./composer.json to its original content.

Which I don't understand because I definitely have curl installed:

$ curl --version
curl 7.53.1 (x86_64-apple-darwin15.6.0) libcurl/7.53.1 OpenSSL/1.0.2k zlib/1.2.5 nghttp2/1.20.0
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp 
Features: IPv6 Largefile NTLM NTLM_WB SSL libz TLS-SRP HTTP2 UnixSockets HTTPS-proxy

And on top of that, it's picked up by php

$ php --ri curl

curl

cURL support => enabled
cURL Information => 7.43.0
Age => 3
Features
AsynchDNS => Yes
CharConv => No
Debug => No
GSS-Negotiate => No
IDN => No
IPv6 => Yes
krb4 => No
Largefile => Yes
libz => Yes
NTLM => Yes
NTLMWB => Yes
SPNEGO => Yes
SSL => Yes
SSPI => No
TLS-SRP => No
HTTP2 => No
GSSAPI => Yes
KERBEROS5 => Yes
UNIX_SOCKETS => Yes
Protocols => dict, file, ftp, ftps, gopher, http, https, imap, imaps, ldap, ldaps, pop3, pop3s, rtsp, smb, smbs, smtp, smtps, telnet, tftp
Host => x86_64-apple-darwin15.0
SSL Version => SecureTransport
ZLib Version => 1.2.5

Any ideas?

ExpiredProviderToken : The provider token is stale and a new token should be generated

I get a lot of errors (in production) : ExpiredProviderToken : The provider token is stale and a new token should be generated.

I think this is due to the lib not refreshing the token as it should do according to Apple documentation.
https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/establishing_a_token-based_connection_to_apns

My workaround for now is to restart the worker but i think the lib should be proactive. I'm working on a PR.

Anyone else experiencing this issue ?

ErrorException in Client.php 99: Undefined offset: 1

Hello, I've followed the Readme, and when triggering $client->push() via Laravel, I receive the follow error. We've tried triggering a notification via Node.js using this tutorial and we were able to successfully trigger a notification.

Any thoughts on how we may be able to fix or troubleshoot this? Thank you,

ErrorException in Client.php line 99:
Undefined offset: 1
in Client.php line 99
at HandleExceptions->handleError(8, 'Undefined offset: 1', '/var/www/domain.com/qa/releases/20170424153008/vendor/edamov/pushok/src/Client.php', 99, array('mh' => resource, 'handles' => array(resource, resource), 'notification' => object(Notification), 'k' => 1, 'request' => object(Request), 'ch' => resource, 'active' => 0, 'mrc' => 0, 'responseCollection' => array(), 'handle' => resource, 'result' => null, 'headers' => '')) in Client.php line 99
at Client->push() in CharacterLikedJob.php line 75
at CharacterLikedJob->handle()

Is ext-gmp really needed?

Tried to install this library, but composer complained about missing ext-gmp php extension. I quickly looked for gmp_ in source tree and didn't found anything.

So is it really needed?

Identifying responses to initially set messages

Hello,

I am trying to somehow find out which of the originally set messages for sending have failed (and identifying them correctly).

Is there a way to do this?

I've checked and i see that in the response only the failed ones are returned so there is no way to distinguish which message is this.

Say for example i am sending 3 messages and N2 fails - how can i identify it (may be with APNS_ID somehow?)

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.