Today we're going to get your server to automatically sound the (textual) alarm when something goes wrong. Using PHP and Laravel, we'll send SMS text message server notifications to the phones of all of your server administrators when there's an exception on your site.
Let's get started!
Click the button below to start the journey.
Here we create a list of people who should be notified if a server error occurs.
The only essential piece of data we need is a
phone_number for each administrator.
Next up, we'll see how to set up the Twilio client.
Next let's see how to handle application exceptions.
Next up let's see how to create a custom message.
Here we create an alert message to send out via text message.
You might also decide to include a picture with your alert message... perhaps a screenshot of the application when the crash happened? A meme image to calm everyone down?
Let's now take a look at how to load the list of administrators.
Now let's look at how to send a text message.
After the message is sent, we print out the phone number we're texting. US and Canadian phone numbers can also send an image with the message. (Other countries will have a shortened url appended pointing to the image.)
That's all, folks!
We've just implemented an automated server notification system that can push out server alerts if (ahem, when) anything goes wrong. Now let's look at some other great features you might like to add.
PHP and Twilio - such a great combination. Here are just two other excellent tutorials for you to try out:
Increase the security of your login system by verifying a user's mobile phone in addition to their password.
Send your customers a text message when they have an upcoming appointment - this tutorial shows you how to do it from a background job.
Thanks for checking out this tutorial! Tweet @twilio to let us know what you think.