:computer: Send notifications to your desktop directly from your PHP script

Last update: May 12, 2022

JoliNotif demo

Total Downloads Latest Stable Version Latest Unstable Version

About JoliNotif

JoliNotif is a cross-platform PHP library to display desktop notifications. It works on Linux, Windows or MacOS.

Requires PHP >= 7.2 (support for PHP 5 was available in version 1.x, for PHP 7.0 and 7.1 in version < 2.1.0).

Note: This library can not be used in a web context (FPM or equivalent). Use it in your CLI scripts or in a CRON

Installation

Use Composer to install JoliNotif in your project:

composer require "jolicode/jolinotif"

Usage

Use the NotifierFactory to create the correct Notifier (adapted to your OS), then use it to send your notification:

include __DIR__.'/vendor/autoload.php';

use Joli\JoliNotif\Notification;
use Joli\JoliNotif\NotifierFactory;

// Create a Notifier
$notifier = NotifierFactory::create();

// Create your notification
$notification =
    (new Notification())
    ->setTitle('Notification title')
    ->setBody('This is the body of your notification')
    ->setIcon(__DIR__.'/path/to/your/icon.png')
    ->addOption('subtitle', 'This is a subtitle') // Only works on macOS (AppleScriptNotifier)
    ->addOption('sound', 'Frog') // Only works on macOS (AppleScriptNotifier)
;

// Send it
$notifier->send($notification);

A shell executable is also provided to use JoliNotif from CLI:

jolinotif --title "Hello" --body "World"

Further documentation

Discover more by reading the docs:

You can see the current and past versions using one of the following:

And finally some meta documentation:

Credits

License

JoliNotif is licensed under the MIT License - see the LICENSE file for details.

GitHub

https://github.com/jolicode/JoliNotif
Comments
  • 1. Added base CLI binary.

    Added base CLI implementation (#29). But I think better to move it into separate repo, somethig like jolicode/jolinotif-cli.

    Installation

    Install package globally:

    $ composer global require jolicode/jolinotif
    

    Note! Make sure to place the ~/.composer/vendor/bin directory (or the equivalent directory for your OS) in your PATH so the transfer executable can be located by your system. Simply add this directory to your PATH in your ~/.bashrc (or ~/.bash_profile) like this:

    $ echo "export PATH=~/.composer/vendor/bin:$PATH" >> ~/.bashrc
    $ source ~/.bashrc
    
    Reviewed by tamtamchik at 2017-10-17 15:20
  • 2. Add support for Linux subsystem on Windows

    This may be a complete edge case, but I needed desktop notifications on the linux subsystem running on windows.

    The good news is that the ToastNotifier works fine, but detecting this situation is a little complex it would seem and there are no definitive answers out there.

    I couldn't find any information on how to detect the linux subsystem running on windows, but the best thing I could find was:

     $isLinuxOnWindows = mb_strpos(strtolower(php_uname()), 'microsoft') !== false
    

    I have implemented this in my setup by extending the NotifierFactory, and rewriting the methods:

    class NotifierFactory extends JoliNotifFactory
    {
        /**
         * @return Notifier[]
         */
        public static function getDefaultNotifiers()
        {
            // Don't retrieve notifiers which are certainly not supported on this
            // system. This helps to lower the number of process to run.
            if (OsHelper::isUnix() && !mb_strpos(strtolower(php_uname()), 'microsoft')) {
                return self::getUnixNotifiers();
            }
    
            return self::getWindowsNotifiers();
        }
    
        /**
         * @return Notifier[]
         */
        private static function getWindowsNotifiers()
        {
            return [
                new ToasterBashWindowsNotifier(),
                new ToasterNotifier(),
                new NotifuNotifier(),
            ];
        }
    }
    

    And then creating a ToasterBashWindowsNotifier that just extends ToasterNotifier:

    class ToasterBashWindowsNotifier extends ToasterNotifier
    {
        /**
         * {@inheritdoc}
         */
        public function canBeUsed()
        {
            return OsHelper::isUnix() && mb_strpos(strtolower(php_uname()), 'microsoft');
        }
    }
    

    and all works now as expected, with notifications popping up as normal.

    The only thing I've found is that icons seem to break it at the moment.

    I haven't looked in detail, but my guess would be that:

    • Notifier expects a path it can resolve in the current OS, so passing a windows style path means the icon doesn't even try to get displayed when running in Linux (it can't find the file). So e.g. passing C:\myapp\myicon.png doesn't work.
    • Toast expects a path it can resolve in Windows, and passing a Linux path causes it to fail - so passing mnt/c/myapp/myicon.png doesn't work.

    I've tracked this down to the 'setIcon' function on the notification, where it does a 'realpath' which turns to null if a windows path is given on the linux subsystem - fuuuuuu.

    Icons aren't 100% important to me, so I can forgo supporting them atm.

    I did have a thought that Toast might be able to support some sort of base64 encoded png - but I can't get it to work.

    Reviewed by manticorp at 2018-01-18 09:42
  • 3. No notification with Windows 10

    Windows 10 Mozilla & Chrome No Internal 500 Error

    The code structure looks like the below.

    <?php
    	ini_set('display_errors', 1);
    	ini_set('display_startup_errors', 1);
    	error_reporting(E_ALL | E_STRICT);
    	require_once '.../vendor/autoload.php';
    	
    	use Joli\JoliNotif\Notification;
    	use Joli\JoliNotif\NotifierFactory;
    
    // Create a Notifier
    	$notifier = NotifierFactory::create();
    
    // Create your notification
    	$notification =
    		(new Notification())
    			->setTitle('Notification title')
    			->setBody('This is the body of your notification')
    	;
    
    // Send it
    	$notifier->send($notification);
    

    Where is the error? Thank you.

    Reviewed by emresaracoglu at 2017-10-26 17:02
  • 4. Icon not shown in desktop notifier

    Hi, the desktop notifier works fine, but even adding the code resource_path('image.png') the image is not showing. I read some other posts for which it would need required to install other package into the OSX o Windows pc, but this cannot be asked to all users using this feature.

    Any solution?

    Reviewed by Echecivuole at 2021-02-11 12:18
  • 5. Trigger the notification from a webapp

    Greate project you got here, I was wondering if its posible to trigger this notifications from a webapp. I tried but the notification doesn't show. If I run the example from the terninal then it shows. Any pointers will be greatly appreciated. From web screen shot 2018-06-09 at 21 19 04 From terminal screen shot 2018-06-09 at 21 19 25 screen shot 2018-06-09 at 21 19 47

    Reviewed by mwakaambrose at 2018-06-09 18:27
  • 6. Not working if script run from cron

    Ubuntu 14..04 Trying to run file with notifier directly - works. Trying to run in cron, like:

    • * * * * php /path/notifier.php Nothing happens.

    root or my own user - not working log says script is run ok

    Can I run it from cron to get result?

    Reviewed by neTpyceB at 2015-06-05 12:54
  • 7. Update symfony/process dependency

    Is it possible to update to also work with symfony/process v5?

    I'm having a dependency issue with other projects that depend on JoliNotif, but have installed symfony/process v5.

    Reviewed by thiagolcks at 2020-01-09 13:01
  • 8. use .gitattributes file to limit zip payload size

    This PR adds export-ignore capability via a .gitattributes.

    Basically this allows github to only send the relevant source files in the .zip/.tar.gz files when composer is installing them. Doing so limits the file size needed to transfer and keeps unnecessary development files (tests/docs/etc) out of production environments.

    You can read more about .gitattributes here

    Reviewed by tomschlick at 2018-03-28 19:34
  • 9. Can't get notifications to work in cron

    Hi, I've read the docs on cron, as well as #13.

    I've performed all the suggested steps but can't get the notifications working from cron:

    * * * * * env DISPLAY=:0 php /home/benjamin/script.php
    

    I verified that the cronjob runs fine. I verified my $DISPLAY:

    $ echo $DISPLAY
    :0
    

    I've run the suggested xhost command as well:

    xhost +local:
    

    But same, no notifications. I'm using Zorin OS 15.3, based on Ubuntu 18.04.

    Any idea how to make notifications work in cron?

    Reviewed by BenMorel at 2021-02-09 18:00
  • 10. Replace Windows 8+ notifier?

    In https://github.com/mikaelbr/node-notifier/commit/61fafc50c387fab2c53f3883af7d53f53209b0c3, they changed the replaced the windows 8+ notifier (Toaster) by a new one: https://github.com/KDE/snoretoast Check whether we would benefit to switch to it inside JoliNotif

    Reviewed by pyrech at 2017-11-22 16:44
  • 11. Synology DSM 6.1 Not working

    Synology DS416+ Php : 5.6 Apache : 2.6 ALL module php active

    message: No supported notifier

    I copied the directory on a mac with a MAMP, everything works, but impossible to run on synology, an idea?

    merci

    Reviewed by fpardigon at 2017-11-20 09:09
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

Mar 26, 2019
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

May 21, 2022
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:

Apr 26, 2022
This package allows you to send notifications to Microsoft Teams.
This package allows you to send notifications to Microsoft Teams.

Teams connector This package allows you to send notifications to Microsoft Teams. Installation You can install the package using the Composer package

May 6, 2022
Larafirebase is a package thats offers you to send push notifications or custom messages via Firebase in Laravel.
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

May 6, 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.

May 12, 2022
Takes care of Apple push notifications (APNS) in your PHP projects.

Notificato Notificato takes care of push notifications in your PHP projects. Italian: notificato è: participio passato English: notified Why use Notif

Apr 17, 2022
Takes care of Apple push notifications (APNS) in your PHP projects.

Notificato Notificato takes care of push notifications in your PHP projects. Italian: notificato è: participio passato English: notified Why use Notif

Apr 17, 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

May 9, 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

Mar 25, 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

May 9, 2022
A very lightweight library to handle notifications the smart way.
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

May 9, 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

May 21, 2022
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.

Feb 8, 2022
Laravel package to launch toast notifications.
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

Mar 14, 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

Mar 18, 2022
Flexible Flash notifications for Laravel
Flexible Flash notifications for Laravel

Introduction Laravel Notify is a package that lets you add custom notifications to your project. A diverse range of notification design is available.

May 23, 2022
A package to simplify automating future notifications and reminders in Laravel
A package to simplify automating future notifications and reminders in Laravel

Laravel Snooze Schedule future notifications and reminders in Laravel Why use this package? Ever wanted to schedule a future notification to go out at

May 11, 2022
📨 Facebook Notifications Channel for Laravel
📨 Facebook Notifications Channel for Laravel

Facebook Notifications Channel for Laravel This package makes it easy to send notifications using the Facebook Messenger with Laravel. Contents Instal

Apr 13, 2022