Monthly Archives: August 2010

Notifying your development team when a git commit is made

My last writeup, looked at how to write a pre-commit hook for your git repository that would not allow you to submit broken PHP code. This time, I’ll show you how to use the .git/hooks/post-commit hook in order to notify all of your development members when a commit has been made successfully. It is very important to understand the environment that git runs in. In my current development setup, only trusted developers get access to git and the helper scripts. By the time I have a hijacked rogue developer account messing with our repositories, I have much bigger problems on my hand. This is why I have setup a common place on my server to store helper scripts and other utilities that any of our developers can use. This is by no means the NSA brand secure way of doing things, but that discussion is a whole other topic.
Read more »

PHP Syntax Checker For Git Update. Test Only Files In The Commit

After my first article on working with git pre-commit hooks, I found a small issue that could cause a developer not to commit, even if all of the code they want to commit is ok. The problem comes with files that are recognized as change, but will not be part of the commit. Luckily sed has an easy solution to this problem. My new git hook now looks like this:

git status |  sed '/# Changed but not updated:/,$d' | sed '/# Untracked files:/,$d' |cut -c 3- | egrep  '^(modified|new file)' | egrep '\.(php|html)$' | awk -F: '{ gsub(/[[:space:]]*/,"", $2); print $2}' | xargs -n1 -r php -l

By using sed, we knock out every line below the “Changed but not updated”, and “Untracked files” sections in the commit message. This way, if you have other sections of code that you are working on, but not pushing into this commit.

PHP syntax checker for Git repository changes

So I was reading this article about writing a php lint checker, that would check your php files for syntax errors before commit. Since I use git, I decided to write something similar. I put this in .git/hooks/pre-commit and made that hook executable. So far it’s working very well.

git status | cut -c 3- | egrep  '^(modified|new file)' | egrep '\.(php|html)$' |awk -F: '{ gsub(/[[:space:]]*/,"", $2); print $2}' |xargs -n1 php -l

In Linux, you can take the output of one command, and make it the input of the next command using the pipe (shift \) character. So let’s break down this command and see how this helps us keep developers from committing php code with errors.
Read more »

PHP 5.3 Deprecation Detector

With the release of PHP 5.2.14, the PHP 5.2.x branch has reached end of support. Also many people in the community pushing very hard for php 5.3 adoption. In a perfect world, this would be a very easy process and all of your code would just roll over and work perfectly. This however is nothing like a perfect world. If you use a managed hosting solution, many are still requiring you use php 5.1 since it is the latest stable release in the RHEL repositories. And if that wasn’t enough, php 5.3 deprecates a decent bit of functionality that many older scripts rely on. You can find a list of deprecated functionality in the php manual.

The functionality still works in PHP 5.3, however it now throws a E_DEPRECATED error. I’ve read many blogs who say the best fix for this is to use the following:

// WRONG !!!!!
error_reporting(E_ALL &~ E_DEPRECATED);

Sadly, this code only hides the messages from you and does nothing to actually help solve the problem. This would be like telling someone who is being chased by your favorite movie monster to just close their eyes and they won’t get hacked to bits! That doesn’t work in the movies, and I assure you it doesn’t work in your production environment either. Luckily while the monster is hacking your friend to bits you can quickly put in place a solution that will help you fix these problems using only MySQL and standard PHP functionality.
Read more »

New Blog

Things at work are finally calming down a little bit! Now I can finally update my blog, and move it to the new cluster at work. I should have everything ported over to the new setup shortly, so stay tuned. I will also have a new blog post coming up shortly, so stay tuned!