PHP Lint has got your back

Hopefully, you have one of those friends who has your back, who will step in and stop you from making a really, really stupid mistake. Because we all are fallible and whether it be in a moment of rage, or just because we are in a rush, we will make mistakes.

This is why I have PHP Lint added as a pre-commit hook on my PHP Project repos. It only takes a minute to set it up and will have you a ton of time, and headache in the future.

First, you need to make sure you have PHP Lint installed on your system. If you are a PHP developer, then the chances are you have it.

Next go to you PHP project .git directory and add the following code to the file .git/hooks/pre-commit


And that should be it. Now every time you do a commit on some PHP code, your git workflow will send each file through the PHP Linter to check for errors. See the example below

Most editors will show you when you make an error, but we are rushing and don't notice that we forgot to add a semi-colon.

routes_php____Documents_GitRepos_DiegoDev_iParq_core_app_Http__-_VIM

We add the file and attempt to do a commit but because of the hook, Git will refuse to commit the files, and we can sleep easier at night knowing we can't accidentally send broken code to our repo.

2__eric_DiegoDev____Documents_GitRepos_DiegoDev_iParq_core__zsh_

One thing to note, this git hook will only parse the files you are committing and not the entire project. Meaning if you have a co-working was not doing linting, and you pull in their changes but don't touch the file, your commit will not catch it.

What time is it?!?!

When you heard that phrase in the 80's, you knew things were about to get funky. However, in the coding world, dealing with dates and time can be a real pain. I did a presentation for our Laravel User Group about a package that I enjoy called Carbon which makes working with dates and times a ton easier.

Check it out.

Talking Laravel

If you know me, you know I am a sucker for a good framework. Doesn't matter the language I am using, I will typically look for the hottest framework on the platform when I start a project.

In my primary development world of PHP, that framework had been cakePHP for a very long time. I had tried several others, but none of them stuck with me like cake did, that was up until a few years ago when a friend with our San Diego PHP User Group started pushing another framework on me called Laravel.

In that time, I've taken the Laravel framework further that I have any other including starting a development group that specializes in the framework. As typical, when I do something I like to submerge myself totally in it, and it wasn't too long before I found myself running a User Group for the Laravel framework.

During that time, I've had the opportunity to speak with a few of the key members of the Laravel community. The following two videos are interviews I did with Taylor Otwell (@taylorotwell) who is the creator of the Laravel Framework. The second video in my interview with Jeffrey Way (@jeffrey_way) who I consider the head educator for Laravel. Enjoyed talking with both these guys. They were super friendly and very, very accommodating.

Enjoy

First up is Taylor Otwell, the creator of Laravel. Great discussion with him.

This is Jeffrey Way's video, we had some major auto problems this night, sorry about that. We were able to mute everything when Jeffrey speaks. Also, the video should start at about the 15-minute mark. Everything before that is just some typical User Group meeting stuff.

My PHPStorm Gotham Theme

Inspired by one of my favorite Vim colorscheme vim-gotham, I created a very dark color theme for PHPStorm. You can download it here. Screenshot here.

To install just place the ICLS file in your PHPStorm directory with your other color themes. On my Mac that that location is ~/Library/Preferences/WebIde80/colors.

PHPStorm Gotham Theme

PHP Unable to send email from web application .. (but commandline works)

This issue seems to have popped up a couple times over the past couple weeks so I figure I would capture the resolution here in the event someone stumbles onto this post and it's able to help them. Security is rarely convenient and this is an example of that.

Symptom:

CentOS machine running current on patches and running a current version of PHP, let's say PHP 5.3 or higher. PHP script is able to sent email from the command line, but when trying to send an email with PHP through the web browser it fails. Actually it doesn't "fail" it just doesn't seem to ever send.

Resolution:

SELinux is running on the machine and is preventing the Apache process to send out emails. There are a couple approaches you can take for this. To quickly test and confirm that the problem is in fact SELinux, and not something else, you can temporarily disable SELinux.

  • First verify SELinux is running with the command (as root) getenforce
  • Next, if SELinux is running you can disable with the command, again as root, setenforce Permissive

 

SELinux with be disable until you reboot the machine or enable it with setenforce Enforcing. You can permanently disable SELinux is you so desire editing the file /etc/sysconfig/selinux and changing the setting SELINUX=

Test your PHP Mail functionality now from the web application. If it works then you need to have SELinux allow the apache process to send emails. In order to do this, run the commands

  • setsebool -P httpd_can_sendmail 1
  • setsebool -P httpd_can_network_connect 1

 

You should now be able to re-enable SELinux and successfully send emails from your application in the browser.

My SDPHP Composer Presentation

A little while back I did a lightning talk at one of our SDPHP MeetUps on Composer. Composer is a fantastic tool and one that will change the way you approach PHP development. Using and managing external packages on a per project level has never been so easy in the PHP world.

I kept forgetting to publish my slides so for what it's worth, here they are.

 

The new PHP – Programming – O’Reilly Media

If your organization has written off PHP from being a possible solution to its development needs, you may want to rethink that decision. PHP is making a strong comeback and with developers who have years of experience under their belt, a language that has matured with the Internet it helps run, and now new features, stronger communities, and interoperability high on everyone's priority list, PHP is once again a great solution for any development need. 

The programming language many love to hate is experiencing a renaissance. This is not your parents' PHP. The new PHP is a more mature language with community standards,...

Some useful git alias commands

Just a few useful git aliases I've stumbled upon on the net which I've found useful and use on a pretty regular basis.

Git things done

git-logo-cc-by-300x300Been meaning to post this for a while. I've been using Git for a number of years now and my last two jobs had me using it heavily. I love git and honestly have managed to block the memories of what my life was like when I tried to manage my version control life with Subversion.

We've also been discussing Git a lot in our SDPHP Group.  I am not going to get into a long post about the coolness of Git and why you should be using it, that is kind of an old discussion at this point. If you are not using Git nowadays I will assume you (a) Don't want to use Git, (b) Don't have a good enough understanding of Git, (c) Don't know what Git is. If you are in category (c) you are probably not a developer and this will be of no interest to you. If you are in category (a), well then I am sure you have your reasons and they are valid. If you are in category (b) then let me share a few things with you. First are some links to some great resources on how to use Git. These groups know what they are talking about and do a fantastic job explaining things, way better than I could ever do.

Helpful links

I also have a couple of presentations I can share with you. The first one was by John Congdon (@johncongdon) and was presented to the SDPHP Group at our monthly meetup Downtown back on Sept 11

I also did a smaller presentation to the SDPHP Study Group earlier on Aug 26

I hope you find some of this information helpful and/or useful.

Viming Safely

As I mentioned a couple of post ago, I started a new job in which I am doing more heavy development, and I am loving it. Now I am a very paranoid programmer and I am this way because I’ve destroyed hours of work with some poorly coded lines. As a result I typically backup the files I am working on before I edit them and this has saved me a few times. Couple this with the fact I am working in unfamiliar code of the new job and I find myself doing a quick ‘cp’ before every ‘vi’.

Something else about me, I am very lazy and I like to automate as much of my life as possible. With this, I created a nice little BASH function to handle this task for me.

It’s pretty basic and I add this to my .bash_profile. Now when I type ‘evim filename’, this little function will make a copy of the file in a Backup folder I defined before launching it with Vim. It will also add a time stamp as part of the backed up filename.

Caching: A Brief Overview

Another SDPHP MeetUp last night and another good talk. Aaron Scherer (@aequasi) did a great job discussing different types of Cache solutions such as OpCode Caches (APC, Zend Optimizer, eAccelerator, XCache, and HipHop) and Data Caches (APC, Memcached, and Redis). Worth a click through.

Encryption: It’s For More Than Just Password

Earlier this week John Congdon gave this talk at tek13, one of the top PHP Conferences. I didn't get a chance to attend the conference this year but I did get to see a preview of the talk a couple of times as John practiced his presentation on the SDPHP group. It's very informative and has me really looking forward to a couple new features that should be released in the next version of PHP version 5.5.

2 Weeks as a Programmer

Screenshot_5_13_13_5_46_PM-3I am starting the 3rd week of my journey; you see I am a “seasoned” IT guy. I’ve been working in the IT industry professionally, in some form or fashion, for some years. I’ve been tinkering with computers longer than that. My first computer was a TRS80-CoCo2 I got for Christmas, I want to say back in 1984.

The first thing I did was teach myself BASIC. I would spend hours coding small applications that didn’t do much of anything. I also started to tinker around with how the computer worked, how did it communicate with my dot-matrix printer or the joystick. This opened up my vision of the field of computers a lot.

As an adult, I found myself in the IT field. This wasn’t that surprising. I had found myself on the track of an Operations guy. You may ask yourself “What is an ‘Operations Guy’?”, Anything short of programming or one of the specialized fields like security, databases, etc. Ops is the heart of everything, making the systems talk to each other and typically the guys who work the odd hours, weekends and holiday to make changes and not impact day-to-day production. We are talking networking, hardware, backups, managing, monitoring, patching, so on and so on.

This is a great field to build a career on, my only problem was I love programming. I mean its one of the things I am passionate about. For years I was a hobby developer, building small applications here and there on the side. I was also fortunate in the sense I always seem to manage to have small development task at work. The longer I worked in the IT field, the more I wanted to focus on development.

A few years back the phrase “DevOps” was gaining popularity and I tried to position myself more and more into a DevOps role. At the time, I was working for a Fortune 100 company. Very corporate in its ways and very slow-moving. They pretty much had the opposite philosophy, leaning more to people becoming very specialized in a particular field or task. About a year ago I decided to make a change and took on a role with a much smaller company in hopes to develop more of the DevOps role. At first, it was very promising but eventually it also turned into a typically Operations position.

All, this time, I continued to better my development skills. Learning as much as I could from languages to best practices. I got more and more involved with the development community and developed some great connections and friendships. When I expressed how unsatisfied I was with the direction my job was taking it was through their encouragement I decided to take somewhat of a leap and look for a position that was more focused on development.

Today I start my 3rd week as a developer. I will chronicle this adventure here.

Awesome Free PHP Resources: Web & PHP Magazine

I'm doing a little cross posting here to promote a post I wrote on the SDPHP site:

There are a ton of good PHP resources out on the net, both free and paid. Web & PHP Magazine is one of those resources that raises that bar from your typical smart developer posting blog articles on the weekend to a very polished, well-organized publication. Best of all, IT’S FREE!!

Rest of the story Awesome Free PHP Resources: Web & PHP Magazine.

Asking Github how it’s feeling

One recent project I worked on depended very heavily on Github. If you don't know what Github is it's a hosting service for projects that uses Git version control and if I really needed to explain that to you then the rest of this post probably won't do much for you.

The problem with depending on external services and API is that when they are having a bad day, then you are probably having a bad day. The project I was a part of was a Node application that would have to be built and rebuilt several times on several different machines, we are talking in the thousands. This application would reach out to Github for several modules which were essential to the build process. Needless to say there are ways to architect this solution to remove this dependency but that isn't the point of this post 😉

Github has a great status page which does a good job at keeping you informed on the current going on with the Github platform but the problem with it is you need to go to the page, get the status, and if there is an issue continually return to see if there are any updates. Thanks to developer Romin Irani (@iromin on twitter) you can now interact with Github over IM and more importantly have his GitHub Status Bot send you notifications whenever Github has any sort of disruption, planned or otherwise.

GitHub Status Bot is pretty simple and easy to use. Its worth noting that GitHub Status Bot is not an "official" Github Bot and is hosted Google AppEngine. Romin Irani also makes his source code available on Github

Using GitHub Status Bot is pretty straight forward

  • First, simply add githubstatusbot@appspot.com to your Gtalk buddy list
  • Once added send a message to the bot by typing 'help'. This will provide you a list of commands that the bot will respond to.

GitHub Status Bot - Help

  • 'status' gives you the current system status

Screenshot_1_26_13_10_17_PM-2

  • 'last-message' gets the last human communication, status, and timestamp.

Screenshot_1_26_13_10_23_PM

  • 'messages' will get you a list of the most recent communications with status and timestamp.

Screenshot_1_26_13_10_28_PM

  • 'subscribe' is a key command, what this does is lets the bot know you want to be notified via Google Talk if GitHub is down.

Screenshot_1_26_13_10_34_PM

  • 'unsubscribe' will remove yourself from any 'GitHub is down' status updates. I've found, unless I was having issues or needed to keep a close eye on Github that the status message will tend to get a little chatty for day to day following.

Screenshot_1_26_13_10_38_PM

  • And finally if you just want to be reminded who you have to thank for this awesome service, and what version you are on, type in 'about'

Screenshot_1_26_13_10_43_PM

That's pretty much it, hope you find the GitHub Status Bot as helpful as I do.