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

Overview

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.

Comments
  • Added base CLI binary.

    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
    
    opened by tamtamchik 13
  • Add support for Linux subsystem on Windows

    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.

    enhancement help wanted 
    opened by manticorp 11
  • No notification with Windows 10

    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.

    opened by emresaracoglu 9
  • Icon not shown in desktop notifier

    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?

    opened by Echecivuole 8
  • Trigger the notification from a webapp

    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

    opened by mwakaambrose 6
  • Not working if script run from cron

    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?

    opened by neTpyceB 6
  • Script hangs while notification is visible

    Script hangs while notification is visible

    I'm using JoliNotif with SnoreNotification on Windows.

    When I send a notification, the script then hangs until either the notification is cleared (by clicking it, for example) or the process times-out

    Example of a timeout:

       Symfony\Component\Process\Exception\ProcessTimedOutException 
    
      The process ""W:\app\vendor\jolicode\jolinotif/bin/snoreToast/snoretoast-x86.exe" -m "With Failures" -t "artisan test finished"" exceeded the timeout of 60 seconds.
    

    Using $process->start() instead of $process->run() in the CliBasedNotifier removes the hang.

    https://github.com/jolicode/JoliNotif/blob/main/src/Notifier/CliBasedNotifier.php#L88

    Is there a reason to use run() instead of start()? (or what about adding an option to specify?)

    opened by Patabugen 5
  • Update symfony/process dependency

    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.

    opened by thiagolcks 5
  • use .gitattributes file to limit zip payload size

    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

    opened by tomschlick 5
  • Can't get notifications to work in cron

    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?

    bug 
    opened by BenMorel 4
  • Replace Windows 8+ notifier?

    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

    enhancement help wanted Hacktoberfest 
    opened by pyrech 4
Releases(v2.5.0)
Owner
JoliCode
We build quality Web and mobile applications.
JoliCode
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
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
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
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

skrepr 20 Oct 4, 2022
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
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 notifications using RocketChat with Laravel 9.0+.

laravel-rocket-chat-notifications Introduction This package makes it easy to send notifications using RocketChat with Laravel 9.0+. Contents Installat

Team Nifty GmbH 25 Dec 1, 2022
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
Service that helps you to send notifications for a series of failed exceptions.

Laravel Failure Notifier This package helps you to track your exceptions and do what you want to do with them such as sending an SMS or and Email. You

Kamyar Gerami 7 Nov 26, 2022
It's Pimcore Bundle to send notifications to Google Chat, Slack or Email from admin panel inside Pimcore

Send notifications to Discord, Google Chat, Slack and more from Pimcore It's Pimcore Bundle to send notifications to Discord, Google Chat, Slack, Tele

LemonMind.com 6 Aug 31, 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

Mathijs Kadijk 223 Sep 28, 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

Mathijs Kadijk 223 Sep 28, 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
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
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 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