Takes care of Apple push notifications (APNS) in your PHP projects.

Overview

Notificato Build Status of Master

Notificato takes care of push notifications in your PHP projects.

Italian: notificato è: participio passato English: notified

Why use Notificato instead of X?

Notificato has some advantages not all other PHP push libraries have:

  1. Supports multiple APNS certificates, so you can push to multiple Apps/Passbook Passes
  2. Takes excellent care of PHPs buggy SSL-sockets, handles quirks and error responses correctly
  3. Well tested with unit tests and nice Object-Oriented structure

Installation

Installation with Composer is recommended. Run the require command to add Notificato to your project:

composer require wrep/notificato

Suggestion: There is also a Notificato for Symfony bundle available, highly recommended for Symfony2 & Symfony3 users.

Getting started

  1. Take a look at the snippet below for a impression how Notificato works
  2. Read the documentation it will help you with common use cases
  3. Check out the API docs for a deeper understanding what Notificato is capable of
<?php
// This imports the Composer autoloader
require_once('vendor/autoload.php');

use Wrep\Notificato\Notificato;

class GettingStarted
{
	/**
	 * This example sends one pushnotification with an alert to Apples production push servers
	 */
	public function sendOnePushNotification()
	{
		// First we get a Notificato instance and tell it what certificate to use as default certificate
		$notificato = new Notificato('./certificate.pem', 'passphrase-to-use');

		// Now we get a fresh messagebuilder from Notificato
		//  This message will be send to device with pushtoken 'fffff...'
		//  it will automaticly be associated with the default certificate
		//  and we will set the red badge on the App icon to 1
		$message = $notificato->messageBuilder()
								->setDeviceToken('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff')
								->setBadge(1)
								->build();

		// The message is ready, let's send it!
		//  Be aware that this method is blocking and on failure Notificato will retry if necessary
		$messageEnvelope = $notificato->send($message);

		// The returned envelope contains usefull information about how many retries where needed and if sending succeeded
		echo $messageEnvelope->getFinalStatusDescription();
	}

	/**
	 * This example reads all unregistered devices from Apples feedback service
	 */
	public function readFeedbackService()
	{
		// First we get the a Notificato instance and tell it what certificate to use as default certificate
		$notificato = new Notificato('./certificate.pem', 'passphrase-to-use');

		// Now read all "tuples" from the feedback service, be aware that this method is blocking
		$tuples = $notificato->receiveFeedback();

		// The tuples contain information about what device unregistered and when it did unregister.
		//  Don't forget to check if the device reregistered after the "invaidated at" date!
		foreach ($tuples as $tuple)
		{
			echo 'Device ' . $tuple->getDeviceToken() . ' invalidated at ' . $tuple->getInvalidatedAt()->format(\DateTime::ISO8601) . PHP_EOL;
		}
	}
}

$gettingStarted = new GettingStarted();
$gettingStarted->sendOnePushNotification();
$gettingStarted->readFeedbackService();

Contribute

We'll love contributions, read Contribute.md for some more info on what you can do and stuff that you should know if you want to help!

License & Credits

Notificato is released under the MIT License by Mathijs Kadijk, so feel free to use it in commercial and non-commercial projects.

Comments
  • SSL3_WRITE_PENDING warnings while sending lot of push-alerts

    SSL3_WRITE_PENDING warnings while sending lot of push-alerts

    WARNING

    fwrite(): SSL operation failed with code 1. OpenSSL Error messages: error:1409F07F:SSL routines:SSL3_WRITE_PENDING:bad write retry

    /Wrep/Notificato/Apns/Gateway.php at line 107. {"messageEnvelope":"[object](Wrep\Notificato\Apns\MessageEnvelope: {})","binaryMessage":null,"bytesSend":0,"retryMessageEnvelope":"[object](Wrep\Notificato\Apns\MessageEnvelope: {})"}

    bug 
    opened by chekalsky 16
  • Execution time

    Execution time

    Hi,

    Everytime I execute the function, I get:

    Fatal error: Maximum execution time of 30 seconds exceeded in ..../Wrep/Notificato/Apns/Gateway.php on line 173
    

    The push notification is sent, but the server code never resumes. It just keeps running until our server maximum settings.

    opened by pedro380085 9
  • Problem with loading private key

    Problem with loading private key

    Though my setup is correct, i always got this error

    Passphrase given, but the private key in XXX is not encrypted, please make sure you are using the correct certificate/passphrase combination.
    

    Commenting Certificate.php on line 171. solved the problem..

    Push notification sent without problem.

    opened by dexcell 7
  • "Call to a member function setStatus() on a non-object" in Gateway.php

    PHP Fatal error: Call to a member function setStatus() on a non-object in /var/www/sfbackend/releases/20131030144915/vendor/wrep/notificato/src/Wrep/Notificato/Apns/Gateway.php on line 192

    I sometimes get this error. Not sure about it origins but it makes sense because method retrieveMessageEnvelope can return null while on line 192 we have setStatus() call on that return value.

    opened by eXtreme 6
  • Support for variable length of push token

    Support for variable length of push token

    Hi,

    Using Notificato we received some push tokens that were not a hexadecimal with a length of 64. In the APNs documentation it says:

    IMPORTANT
    APNs device tokens are of variable length. Do not hard-code their size.
    

    Is there a specific reason to check on the length. Can you remove this check otherwise?

    // Check if the length of the devicetoken is correct
    if (64 != strlen($deviceToken)) {
         throw new \InvalidArgumentException('Invalid device token given, incorrect length: ' . $deviceToken . ' (' . strlen($deviceToken) . ')');
    }
    
    opened by Tayfun74 5
  • Push notification is not being delivered to device

    Push notification is not being delivered to device

    When I require this package via composer it gives me dependency error for openssl. Now I have updated version of openssl on my mac but it is still giving this error;

    Your requirements could not be resolved to an installable set of packages.
    
      Problem 1
        - Installation request for wrep/notificato ^1.2 -> satisfiable by wrep/notificato[1.2.0].
        - wrep/notificato 1.2.0 requires lib-openssl * -> the requested linked library openssl has the wrong version installed or is missing from your system, make sure to have the extension providing it.
    

    I is not clear from the message that which openssl version is required. Here my current version of openssl; OpenSSL 1.0.2h 3 May 2016 Please let me know if can change any version to make it work?

    opened by tahirwaseer 4
  • Certificate Name (CN) not correctly defining APNS environment

    Certificate Name (CN) not correctly defining APNS environment

    Noticed now Apple are naming their APNS certificates differently.

    They are named Apple Push Services rather than specificly Production or Development

    https://github.com/mac-cain13/notificato/blob/master/src/Wrep/Notificato/Apns/Certificate.php#L149

    As they are now merging the two, unsure how accurately it would detect the correct environment to use, however got it working by adding an extra condition to catch the updated name and point to production.

    opened by chorsnell 4
  • Error: You MUST recompile PHP with a larger value of FD_SETSIZE

    Error: You MUST recompile PHP with a larger value of FD_SETSIZE

    Hi, I am having the following error poping up:

    PHP Warning: stream_select(): You MUST recompile PHP with a larger value of FD_SETSIZE. It is set to 1024, but you have descriptors numbered at least as high as 1048. --enable-fd-setsize=2048 is recommended, but you may want to set it to equal the maximum number of open files supported by your system, in order to avoid seeing this error again at a later date. in /data/web/virtuals/clients/client1/web1094/web/v2/vendor/wrep/notificato/src/Wrep/Notificato/Apns/Gateway.php:152

    I know its not related directly to Notificato, but I was wondering if anybody had this issu and if there is some kind of workaround.

    Thanks

    opened by adusak 3
  • How to add the custom information with the push notification?

    How to add the custom information with the push notification?

    I am sending push notifications from php job application to iphone. I am sending push notifications regarding new jobs. Is this possible that when user click on the view of push notification pop up , then user redirect to the particular job in the device.

    I mean I wanted to know can I send any custom data with push notification like access_token, something else....so that Iphone end Can retrieve and show the particular job ?

    Regardless of the language and library you use, the push notification payload is a JSON payload: { "aps": { "badge": 10, "alert": "Hello world!", "sound": "cat.caf" } }

    We want add custom information with the push notification. Like below

    { "aps": { "badge": 10, "alert": "Hello world!", "sound": "cat.caf" }, "access_token": 1 }

    Thanks.

    opened by manifsp 2
  • Permanent background process

    Permanent background process

    Can you share your thoughts what is the best way to implement the permanent process of checking for newly added notifications and occasionally sending the new ones with your "Notificato"? Currently i am using php module "memory cache", but i wonder if i missed something and there is a better solution.

    opened by dmitriigaidarji 2
  • PHP Fatal error:  Uncaught exception 'Wrep\Notificato\Apns\Exception\InvalidCertificateException' with message 'Could not detect APNS environment based on the CN string

    PHP Fatal error: Uncaught exception 'Wrep\Notificato\Apns\Exception\InvalidCertificateException' with message 'Could not detect APNS environment based on the CN string

    is this because of the new way production certificates are created with apple apns.. no longer is there a dev or product there all under one umbrella now

    opened by northkode 1
  • Legacy APNS push notifications

    Legacy APNS push notifications

    Hello,

    Does notificato have a chance to migrate to the Apple replacement HTTP/2 API? https://developer.apple.com/news/?id=uzyxiriy

    Thanks All the best

    opened by sglessard 1
  • Wrep/Notificato/Apns/Gateway.php READ_TIMEOUT

    Wrep/Notificato/Apns/Gateway.php READ_TIMEOUT

    Hi is there a reason why the variable READ_TIMEOUT in SslSocket is not configurable? What we're seeing now is a timeout of 1 second on each push notification request to apple.. because the reply is always empty...

    Push notifications are most of the time fire & forget imho, the reply doesn't matter ...

    Will fork this library and put the variable to 0 but would be nice if this configurable and that I can continue to use this library.

    Thanks!

    opened by jrots 2
  • Make Notification Factory cache certificates, or make the factory implement an interface

    Make Notification Factory cache certificates, or make the factory implement an interface

    I get "bad password" errors when I send multiple notifications in the same process - using a new message builder for each one, creating a new certificate for each (via Notificato::createCertificate method). Simple solution was to cache the certificate objects so they can be used again. But it would be nice if the CertificateFactory supported this. It only caches a default one. I'd like to key the cache off of the pem location. Was going to implement my own CertificateFactory for this, but turns out the setCertificateFactory typehints to the concrete implementation of Apns\CertificateFactory. I can make my own factory and use it outside the scope of this library, but thought I would recommend it to the repo... sorry, no time for PRs!

    enhancement 
    opened by stevenmyhre 1
Releases(1.2.1)
Owner
Mathijs Kadijk
Improves wherever possible and develops tech for the best UX @Q42.
Mathijs Kadijk
Send push notifications to apple devices (iPhone, iPad, iPod).

Apple Apn Push Send push notifications to apple devices (iPhone, iPad, iPod). Support authenticators: Certificate Json Web Token Supported protocols:

Vitaliy Zhuk 157 Dec 1, 2022
ApnsPHP: Apple Push Notification & Feedback Provider

ApnsPHP: Apple Push Notification & Feedback Provider A full set of open source PHP classes to interact with the Apple Push Notification service for th

Immobiliare Labs 1.4k Nov 16, 2022
Standalone PHP library for easy devices notifications push.

NotificationPusher Standalone PHP library for easy devices message notifications push. Feel free to contribute! Thanks. Contributors Cédric Dugat (Aut

Cédric Dugat 1.2k Jan 3, 2023
A PHP Library to easily send push notifications with the Pushwoosh REST Web Services.

php-pushwoosh A PHP Library to easily send push notifications with the Pushwoosh REST Web Services. First sample, creating a Pushwoosh message // Crea

gomoob 63 Sep 28, 2022
Push notifications Library for PHP

Push notifications Library for PHP Supported Protocols Protocol Supported Driver Options APNs (Token Based) ✓ APNs\Token APNs\Token\Option APNs (Certi

Norifumi SUNAOKA 3 Dec 14, 2022
Send Firebase push notifications with Laravel php framework.

FCM Notification Channel for Laravel Send Firebase push notifications with Laravel php framework. Installation You can install this package via compos

Ankur Kumar 23 Oct 31, 2022
Standalone PHP library for easy devices notifications push.

NotificationPusher Standalone PHP library for easy devices message notifications push. Feel free to contribute! Thanks. Contributors Cédric Dugat (Aut

Cédric Dugat 1.2k Jan 3, 2023
Larafirebase is a package thats offers you to send push notifications or custom messages via Firebase in Laravel.

Introduction Larafirebase is a package thats offers you to send push notifications or custom messages via Firebase in Laravel. Firebase Cloud Messagin

Kutia Software Company 264 Jan 7, 2023
Push Notifications using Laravel

laravel-push-notification Push Notifications using Laravel PushNotification::send(['deviceToken1', 'deviceToken2',..], 'Notification Message', 'Action

Webelight Solutions 26 Jul 22, 2022
Laravel package to enable sending push notifications to devices

Laravel Push Notification Package to enable sending push notifications to devices Installation Update your composer.json file to include this package

Davi Nunes 1.2k Sep 27, 2022
WebPush can be used to send notifications to endpoints which server delivers Web Push

WebPush can be used to send notifications to endpoints which server delivers Web Push notifications as described in the Web Push protocol. As it is standardized, you don't have to worry about what server type it relies on.

null 1.5k Jan 7, 2023
This package makes it easy to send web push notifications with Laravel.

Web push notifications channel for Laravel This package makes it easy to send web push notifications with Laravel. Installation You can install the pa

Laravel Notification Channels 564 Jan 3, 2023
:computer: Send notifications to your desktop directly from your PHP script

About JoliNotif JoliNotif is a cross-platform PHP library to display desktop notifications. It works on Linux, Windows or MacOS. Requires PHP >= 7.2 (

JoliCode 1.2k Dec 29, 2022
Notifications in PHP (notify-send, growl, etc) like that.

#Nod Notifications in PHP (notify-send, growl, etc) like that. ##Examples Letting Nod figure out the best Adapter to use (not recommend ATM, only work

Filipe Dobreira 51 Mar 26, 2019
A very lightweight library to handle notifications the smart way.

NAMSHI | Notificator Notificator is a very simple and lightweight library to handle notifications the smart way. It took inspiration from other librar

Namshi 187 Nov 4, 2022
Sends notifications via one or more channels (email, SMS, ...).

Notifier Component The Notifier component sends notifications via one or more channels (email, SMS, ...). Resources Documentation Contributing Report

Symfony 610 Jan 3, 2023
Laravel Security Notifications

This package adds security notifications to warn your users when significant security events occur so that they aren't the next victim of an attacker.

Anteris 5 Feb 8, 2022
Laravel package to launch toast notifications.

Laravel package to launch toast notifications. This package provides assistance when using toast notifications. Using the iziTOAST package, which allo

Anthony Medina 7 Nov 25, 2022
Laravel Subscribable Notifications

Laravel Subscribable Notifications This package allows you to subscribe your app Users to your app Notifications and dispatch them without specifying

Andrés Santibáñez 132 Nov 10, 2022