One of the things that I regularly bake into my own applications is notifications of when things go really bad and need my immediate attention. For this, I use the excellent and simple Pushover service which allows me to send a push notification to my mobile device. In this post, I run through how to set up your application in Pushover and then send a notification via PHP.
Setup Pushover
I am assuming that you have already created your Pushover account. You get a 30-day trial and after that, it is just $5 as a one-off purchase.
From your dashboard scroll down until you see the Your Application section. You can create applications for each of your projects or third-party integrations. As you can see here I have two (AWS GuardDuty and Papertrail) which are services that I use and the rest are my own projects.
Click the “Create an Application/API Token” link which will allow you to create a new application. The form is very straightforward with only the Name and T&Cs tickbox mandatory. I usually set an icon as this gives a visual identification when the notification appears on my device.
Once you have entered your details and clicked the Create Application button you will be taken to a page with your API token for this application. Grab this and your user key from the dashboard as you will need both in the next step.
Sending a Notification via PHP
Sending a push notification is simplicity itself. The small snippet of code below is all you need. just remember to change the token, user and message fields!
curl_setopt_array($ch = curl_init(), array(
CURLOPT_URL => "https://api.pushover.net/1/messages.json",
CURLOPT_POSTFIELDS => array(
"token" => "<your application token>",
"user" => "<your user key>",
"message" => "<your message>",
"CURLOPT_RETURNTRANSFER" => 1,
),
));
curl_exec($ch);
curl_close($ch);
And this is what the output looks like on my watch. All very quick and painless offering instant updates for me on what important things are happening on my applications.