Use Twilio to Programmatically Text Yourself!

Twilio SMS Text Alerts
Screenshot from my Android phone of the SMS Text Messages I sent myself from Twilio (full URLs are redacted)

built a little program that checks book prices and alerts me if the price is low enough.  Recently, I integrated Twilio with it, so that I receive an SMS alert when my program finds a match.  This was surprisingly easy to do.

I’m a PHP wizard, so I wrote it in PHP, and here’s the code to do it.  That’s a github gist, and I had to alter it a bit as not to reveal any top secret code, so you’ll have to finish it a bit to meet your goals, but it should give you a good idea.  It’s fun to implement, because all you have to do is something like this:

$twilio_gateway = new Twilio_Gateway();
$twilio_gateway->text_me( 'This is an alert!' );

I love when code reads like that. So easy to understand what’s going on!

If you’ve never heard of Twilio, you should check them out.  They have APIs for incorporating text messaging, video and voice into your app.  Their developer docs are super easy to follow and they offer a free trial account!  I’m still unsure of how many text messages you get to use with a free trial account, but it’s way more than a handful.

If you’re on their trial account, text messages will include a notice that they were sent from a trial account.  You also can only send messages to phone numbers that you have verified.  That said, if you want to send alerts to yourself for free, Twilio makes that possible.  And if you decide to upgrade to a paid account, it seems that the cost is still going to be pretty cheap for personal use.  I first heard of Twilio while listening to a Software Engineering Daily podcast, and the ad said it was something like a penny a message.  You do have to buy a phone number to send the messages from, but that’s also super cheap.

SMS is a great option for sending alerts, because modern smartphones allow you to designate different notification sounds for each number, so I have a unique sound for when it’s an alert from my program.  The trick is to make sure that the alert only comes in when it’s actually important, as when alerts happen too often, the human brain tends to tune them out.  So the next step is optimizing my program to get better at figuring out when something really is a deal!

Debugging PhpStorm with xDebug on Ubuntu – Solving Common Set-up Problems

Do you love programming in PHP?  If you don’t, could it be your editor/IDE?

As a programmer, the tools you use, and how well you use them, can have a huge impact on your productivity.

How much time have you wasted writing var_dump statements and printing log messages?

What if you could just inspect the contents of a variable whenever you wanted?

That’s what debugging allows you to do, and that’s what I do every day.

Not sure what the array keys are?  Inspect the variable.  Not sure of the object’s properties?  Inspect the variable.  Not sure if a function is running?  Stick a breakpoint on its first line, and see if your program stops execution at that point.

Debugging saves time… But setting up debugging can also take some time, as it requires the installation of xdebug and the correct configuration set-up.  Plus, if you’re using a virtual machine like a vagrant box, you’ll need to set up path mappings.

PhpStorm Has Built-in Debugging for xdebug

See that screenshot?  If you’re trying to get xdebug to work with phpstorm, and you’ve already installed xdebug, then you should go to: Run –> Web Server Debug Validation (For PhpStorm version 2016.3.2, it’s the last option in that Run dropdown menu.)

When that validation box first opens, you’ll probably see an error message.  Click on “validate” and it might work right out of the box. If not, check that the path is set to a location that the web server can serve up. If you already have a project, this can just be the directory to the project.  (By default, Apache only serves up files from within a specific directory, and as programmers we usually put our web apps inside that directory, because then we can view them with a web browser.)

Settings for Ubuntu 16.04 with Apache and PHP 7

If you’re running Ubuntu with Apache and PHP locally, make sure that “Local Web Server or Shared Folder” is selected, and enter the following:

Path to create validation script: /var/www/html/

URL to validation script: http://127.0.0.1/

Click Validate….. and PhpStorm will tell you what’s wrong!!

In this case, it was easy.  I just had to add xdebug.remote_enable=1 to my php.ini file

And then I just had to restart Apache:

systemctl restart apache2

Hope that was helpful!

 

Which PHP Framework should I learn? (2016 Comparison)

I’ve become interested in learning a PHP Framework (in addition to the WordPress CMS) for two reasons.  First, I’ve been looking at PHP job listings and experience working with at least one framework is required for most mid to senior level developer/software engineer jobs.

The second reason I’ve decided to learn a PHP framework is that I have an idea for expanding my Amazon Search program and I like the advice to “always be learning something new.”  I think this advice comes from the book Coders at Work by Peter Seibel, but it’s possible that the advice is really from some other place… But it makes sense that I might as well improve my skills while I’m also improving my application.

So I’ve been spending my last few evenings drawing UML class diagrams (as well as flow charts) to plan out my program’s design.  I also spent a day getting the Laravel framework set up on my development server.  So far, I’ve set up a Laravel program that does basic CRUD and I can see why people want to work with Laravel.  The hardest part, after initial set-up, was not overthinking things!  Laravel has a lot of “syntatic sugar” so the code is easy to write and read, but debugging is a pain because functions are hidden inside of traits and behind facades.

Before choosing Laravel for my project, I did some research on PHP Framework popularity.  I searched the job hunting website Indeed.com for major frameworks along with the keyword PHP.  This is what I found:

Framework Popularity based in Indeed Job Openings

For that graph, I omitted the frameworks with 20 or less mentions, which were Aura, Apigility, and Phalcon.

As you can see, I included both Model-View-Controller (MVC) frameworks as well as Content Management Systems (CMS).   While some applications could use either type of framework, in general a CMS is designed for a blog type site or a site managing a lot of content.

For CMS Frameworks, WordPress beat Drupal by a few hundred listings.  This is for a nationwide search that also included the keyword PHP. This was to hopefully exclude jobs that weren’t true PHP programming jobs (like WordPress front-end design or WordPress website management or WordPress Marketing or WordPress SEO), but because this search included jobs that list PHP as a “nice to have” skill, the actual number of WordPress backend PHP programming jobs is probably significantly lower.

As for the MVC frameworks, Laravel and Zend were the most in-demand, each having over 700 job openings.  One word of caution about this result is that some job lisitngs state something like this “Requires knowledge of an MVC PHP Framework, such as Laravel or Zend.”  In this case, they are just giving an example of a popular one, but if you were familiar with CakePHP or CodeIgniter (both MVC Frameworks), then you would also meet that job qualification.

What PHP framework should I use?

Ultimately, you should either search for local jobs and find companies that you want to work for, or search for open source projects that you are interested in, and use the same frameworks that they are using.

Tip: You can use the website builtwith.com to find out what frameworks and other technology a website is using.

An experienced programmer can learn a new framework with relative ease, so once you have strong experience with one framework, you can probably quickly learn another if needed.

What PHP framework should I LEARN?

Another option for choosing a framework is to look at the availability of tutorials and books.  If you can find a tutorial or book that covers the topics you’ll need for your project, in a learning style that you like, then perhaps you should use that framework.  Finding a good instructor or mentor is GOLD!   So, find the best source for learning whatever it is that you want to do, and then use the same frameworks and tools that they are using.  There are a plethora of code instruction websites that have video tutorials and online courses.  Most do cost something, but I’ve found free access to Lynda.com through my local library, Udacity has deeply discounted sales regularly, and Pluralsight gave me a couple of months free as a promotion, so if you join the mailing lists of these educational sights, you might find a low-cost deal.

 

Do I NEED a PHP Framwork?

Like most everything, there’s both positives and negatives.

Positives:

  •  A good framework will save you time because it provides basic functionality common to
    many programs so you don’t have to reinvent the wheel!
  •  MVC Frameworks help with code organization.
  •  A framework may make it easier for other programmers to understand your code.
  •  A well-established, open source framework means more eyes on the code and lots of
    bugs already fixed

Negatives:

  • Frameworks can take awhile to set-up and learn.
  •  It may be harder to debug code if you don’t understand the framework thoroughly.
  • Applications may be slower and larger if the framework includes a lot of code that is not relevant to your project.
  •  Your application will depend upon the framework’s continued support and updates (you’ll have to update the framework, especially if security issues are discovered.)