Monthly Archives: June 2010

audio alerts for php errors

I tend to keep a log tailing in one console while working in another.

tail is a Linux program that displays the last few lines of a file. If you run tail -f /var/log/httpd/error_log as root, or as your normal user if you’ve set the right permissions, then you will see any errors as they are added to the log.

However, I also tend to get immersed in my coding and not notice any errors until they cause a visual problem.

What I needed was a program that would watch my log, and beep to get my attention if an error was added.

This article explains how to set that up in Fedora.

First, install the program swatch:

[root@ryuk ~]# yum install swatch

Now create /etc/init.d/swatch, which is the startup/shutdown script for the logger:

#!/bin/sh

case "$1" in
'start')
                /usr/bin/swatch --daemon --config-file=/etc/swatch-httpd-errors --tail-file=/var/log/httpd/error_log --pid-file=/var/run/swatch-httpd-errors.pid
                ;;
'stop')
                PID=`cat /var/run/swatch-httpd-errors.pid`
                kill -9 $PID
                ;;
*)
                echo "Usage: $0 { start | stop }"
                ;;
esac
exit 0

Notice the two file locations in the /usr/bin/swatch command – the configuration file location, and the log file to be tailed.

Make the file executable:

[root@ryuk ~]# chmod +x /etc/init.d/swatch

Now create the configuration file, /etc/swatch-httpd-errors:

watchfor /PHP Parse error|PHP Fatal error/
        exec mplayer /home/kae/sounds/beep-8.wav > /dev/null 2> /dev/null

You can have swatch do basically anything, from sending an email, to flashing lights in your face if you have them connected to the computer. All I wanted was a little beep.

Change the exec command to whatever your want.

I started experimenting by having Arnold Schwarzenegger yell “What the hell are you doing??” at me, but that could get annoying for other people. In the end, I changed it to a beep – a very /short/ beep. More of a tick than a beep.

Now start up the daemon:

[root@ryuk ~]# /etc/init.d/swatch start

Create a php script with an error in it, and view it in your browser. You should get a satisfying beep.

If you want to have this run automatically when the laptop boots, add the above command to the /etc/rc.local file.

long beep short beep short beep

Bronwyn’s laptop just “died”. She turned it on, there was a beep sequence (“long short short”), then nothing appeared to happen.

All the lights were on, the fan was running and there appeared to be activity, but nothing showed on the monitor.

The problem, it appears, is that the GPU overheats too easily and was soldered incorrectly to the motherboard by HP (it’s a HP Pavilion dv2000). When it overheats, the solder melts. When the computer is turned off, the solder solidifies and shrinks, breaking the connection with the GPU, causing the laptop to fail to turn on the video when next booted up.

The proper solution is to replace the GPU, or at least to re-solder the connection and improve the thermal flow around the chip. Unfortunately, I’m just not technically able to do that.

The temporary solution is:

  • Place the laptop on a cushion so the air intake ports are blocked.
  • Turn on the laptop.
  • Let it overheat for ten minutes or so. This will melt the solder again, re-establishing the connection.
  • Turn off the laptop.
  • Turn on the laptop.

Obviously, this is a temporary solution until I can get the cash to pay for a new laptop for her. After that, the laptop joins my collection of broken laptops and will be used for something or other that doesn’t need a working video card.

piano grade 2 results arrived

I did the grade 2 exam three weeks ago. The results just arrived: “successfully passed in the second grade examination in Pianoforte with first class honours”

Cool, I’ll shove that certificate up on the piano next to last year’s one.

I’m going for grade 3 in September. Was meant to do grade 2 a few months ago, but couldn’t find anywhere close that would do the examination. The nearest was in Louth, but that’s too far to walk.

Here are the examiner’s notes:

Max Marks Requirements Examiner’s Comments Marks Awarded
15 Scales & Arpeggios Very good. Good choice of speed but make sure you keep it nice and steady! Very good tone. 13
10 Sight Readng Very good. Mind the counting 9
10 Ear Tests Very good. 9
5 Theory Excellent. 5
20 First Piece Sonatina in G: You caught the mood well. Nice fluent performance. Good phrasing, tone, dynamics and technique. 18
20 Second Piece Waltz: Another lovely performance. Very good balance in left hand melody. Great attention to detail. Very enjoyable! 19
20 Third Piece Samba: Excellent rhythm throughout. Very good range of dynamics and good use of arm weight. Good control throughout. Well done! 18
Total/Additional Comments: Congratulations! Keep up the excellent work! 91

As you can guess, I’m pretty happy about this!

I’m hoping the keep up the high marks for the next exam. My teacher says my pieces for that exam are already at “pass” level, so three more months of practice can only improve that!

I’m hoping to have enough money next month (royalties from my last book) to afford a new piano and a camera, so may be able to stick some tunes online soon.

review: Expert PHP5 Tools

In short: great overview of the various tools and processes that can be followed to make working in PHP easy and manageable. I have a new employee here in the office who will be getting this book after me, to quickly bring her up to speed on good practices.

The Good

As you might guess from the “new employee” comment, even though the word “Expert” is in the title, you don’t need to be an expert PHP programmer to use this book. It’s an all-round overview of the programs you might use during your day-to-day programming life for the next few years.

As the author (Dirk Merkel) suggested in the book, some people may disagree with some choices in the book. For example, I am a fervent Vim user, but the book chooses Eclipse as its programming environment of choice.

From a broader point of view, the Eclipse IDE may be the correct one for programmers to use, as it offers much more than just a text editor. As for me, it’s hard to change an old dog’s habits!

The book includes some handy reference notes for various tools, such as SVN or phpDocumentor. It’s good for people that are not used to reading online references for everything to have them all in one book.

Each chapter is immensely in-depth. To the point that it’s almost like each chapter is a mini-book on its own subject. In some cases the chapters include everything you might ever use on those subjects.

For myself, I’m interested to try some of the suggestions in the Continuous Integration chapter and throughout the book, as I already run a few projects where updates are more important than releases. I’m especially interested in integrating SVN with automated testing and style-checking. Test-driven Development is described in the book, and it certainly seems more robust than my current “deadline-driven development” style!

The Bad

There were code samples in there that could have been shortened immensely by choosing a different spacing scheme or reducing the comments. For example, in the Debugging chapter, there is a code sample that goes on for 9 pages. That’s a lot of code to read… If the empty lines and comments had been removed or reduced, Dirk could have cut it down to maybe 4 or 3 pages, making it much more readable in print. As it was, I did my best to read through it, flipping back and forth between pages to find where references went or came from.

The Ugly

Actually, there wasn’t really anything in this book that I’d call ugly, apart from the overly long code examples.

Conclusion

Immensely useful for the professional programmer. Especially a programmer who needs to fit into a team.

I’m no beginner myself, and picked up quite a few tips throughout the book.

Buy this book – it’s worth it.

update: CMS design with jQuery and PHP

EDIT: The CMS that the book is about is available to download here.

I got an “urgent” email recently from my Packt coordinator – she told me that if I kept writing my book at the rate I was writing, then it would end up being about 500 pages.

Thing is, though – it would be tricky to reduce the chapters I’ve already done, as a half explanation is as good as no explanation at all.

So, I looked over the planned chapters again, and saw that the final three could probably be dropped without affecting the core content of the book – they were just more example plugins showing how to integrate various things with the CMS.

The book itself is on how to build a CMS in PHP, that uses jQuery to make administration easier. That has been accomplished already in the existing chapters (1-7).

I suggested to Packt that I would drop the final three chapters and rework the earlier chapters so the book was more easily read (a 40-page chapter is /not/ easy to read).

Got an email back from them yesterday saying that the plan sounded good.

So the current plan is:

  • Finish chapter 8, which is on panels and widgets.
  • Write chapter 9, which will build a plugin demonstrating panels and widgets.
  • Try to break the earlier chapters apart so that there are more chapters, with less pages per chapter.
  • profit

I think I’ll be finished the current chapters within three weeks, then take a week or two to rework the earlier chapters, then another month for rewrites, and finally the book will be published 2/3 weeks later.

So, the book may be out within two months.

After this, I’m taking a break from modern technology to write about baroque technology – I’ll be writing a book on how to build a cheap clavichord.