• Home
  • About
  • Contact
  • tweets by me

    About me
    • Moving from phpUnderControl to Jenkins as CI solution 37 mins ago
    • Reviewing delivered functionality and code and testing in general, important (yet sometimes tedious) work! 4 hrs ago
    • More coffee FTW! 4 hrs ago
    • More updates...
  • Recent Posts

    • Outputting formatted XML using PHP
    • SSH Tunneling across multiple hosts in Linux
    • Pre-commit hook in Git: Running PHPUnit
    • Multiple types of opening braces when matching pairs with the tokenizer/ext
    • Introducing: DocBlox
« Previous Page — Next Page »

My current affairs

Jan 04
Posted on January 4th, 2009 In category Personal 
By mvriel Tagged as affairs  redesign  website 
Teaser of the new Naenius design

Teaser of the new Naenius design

I have neglected some of my contacts and social places. Although I would like to blaim my busy life for it, it is also a matter of just not making time for it.

So to entertain myself and others, I can share that one of the things I am working on is a redesign of my ‘brand’ and website. The logo was renewed during the last redesign and I will continue to use that. The things that needed improvement (IMHO) was that the colors could be lighter, causing a less depressing feeling and an additional reason was that I was in the mood for some graphical tinkering.

An additional benefit is that I am taking into account the twitter posts on my blog and make them less visible. Thus making actual posts more visible and dominant.

Unfortunately I have much to do and far too little time to get anything done (or so it seems these days). So all I can say is that it is underway but when it will exactly launch.. I do not know yet..

No Comments »

Moving to a new host

Dec 20
Posted on December 20th, 2008 In category Maintenance 
By mvriel Tagged as domain  downtime  maintenance  moving  webhost 

What I want is not what I can get at my old host. Thus in order to do get what I want I have decided to move my domains to a new webhost.

I have requested the move to be done monday the 22nd of december at 22.00 hours. I still need to get confirmation but am quite sure all will go ok.

During the move a notice will be placed informing you about the maintenance. This site will be unreachable in the meanwhile.

Now, let’s pray all goes well ;)

No Comments »

Spam has left the building … finally

Dec 18
Posted on December 18th, 2008 In category Personal 
By mvriel Tagged as akismet  anti-spam  missyeh  spam 

I have done it, on the 29th of November I finally activated Akismet and begun cleaning up spam which was still remaining on my blog.

Today, I took the time and the liberty to remove the last spam comments AND write a new (perhaps for some quite uninteresting) blog post. When I started my blog I did not expect to be carpet bombed by this much spam but alas, even I had to undergo this torment. Due to the fact I found myself not interesting enough (yet?) to be spammed did I not bother to activate Akismet and forgot about it. When spam issues arrived I tried several non-interesting and absolutely useless options until MissYeh reminded me off Akismet. I still owe her..

Should anyone be reading this who is thinking about starting his own (WordPress) blog: install Akismet from day 1. It will save you a lot of headache and it will in the end save you a lot of time fixing your blog.

Again a big warm thanks to MissYeh for helping me remember Akismet and thank you to the creators of Akismet for doing such a fine job.

Until next time!

No Comments »

Spam part II

Aug 26
Posted on August 26th, 2008 In category Personal 
By mvriel Tagged as anti-spam  comments  help  spam 

For some reason I seem to have become popular with the spam bots. Not quite the crowd I was hoping for :)

It is not possible for me to keep deleting all spam until I have time to implement anti-spam measures. It is on my to-do list but other (more pressing) matters have priority. Should you have any good suggestions about anti-spam measures on WordPress, let me know!

So.. This blog ain’t dead or unmoderated, just temporarily overrun :)

2 Comments »

The first spam battle, I lost..

Aug 15
Posted on August 15th, 2008 In category Personal 
By mvriel Tagged as comments  fail  spam 

I have had a spam run in the last couple of days and was forced to delete a couple of hundred spam messages.

Despite the fact that I was reviewing every message if it was a valid comment or not (I unfortunately do not get many at the moment) it seems that I have overlooked about 90% of the real comments.

FAIL!

I have now placed a small unobtrusive barrier which might temporarily slow the amount of spam and I must look into the spam issue. It is driving me bonkers..

I sympathize with every other blogger who ever had to deal with this..

No Comments »

PHPWomen Article contest has closed

Aug 01
Posted on August 1st, 2008 In category Development 
By mvriel Tagged as articles  contest  PHP  phpwomen 

The PHPWomen contest has closed. As I had said earlier I have also participated in the contest. I restrained from posting the articles on my blog because it feels unfair to the community at PHPWomen.

In hindsight it would have been convenient if I posted a new blog item whenever I posted a new article. But as with most good ideas, it came too late.

To compensate I will post the titles of the articles that I have written here with a deep link to the content, it is only fair that people actually visit the place where the contest was held IMHO.

So, without further delay, here they come:

  1. Love your class methods
  2. Exceptions: errors on steroids
  3. The art of docblogging

I hope you enjoy the read and if you are there, say hello or share your wisdom on the forums!

No Comments »

Sometimes I temporarily get a life

Jul 31
Posted on July 31st, 2008 In category Personal 
By mvriel Tagged as ball  dog  fenna  ijsselmeer  lake  walk 

There are times when I do not touch a computer, it happens. I like to tabletop roleplay for example and I ‘own’ a dog called Fenna who loves to be active. At these sort of times one might be tempted to say that I temporarily get a life.

My wife suggested today to visit a little beachside at the IJsselmeer, which is a lake in the Netherlands, to allow Fenna to swim for a while. I thought this to be a good idea, given the heat and all, and off we went.

We took two tennis balls with us to throw in the water (for some reason this is the only time balls are of any interest to Fenna?), which resulted in the utter abuse and molestation of one of those poor little balls. As is demonstrated by this picture.

We took this picture after Fenna had a very good time with the ball and she is currently still far too bouncy and happy happy joy joy.

We had pity on the other ball and kept it from her, perhaps next time it will fall victim to what seems a nice and friendly dog ;)

No Comments »

phpWomen contest close to an end

Jul 30
Posted on July 30th, 2008 In category Development 
By mvriel Tagged as articles  contest  PHP  phpwomen 

Tomorrow will be the last day to participate in the phpWomen contest at www.phpwomen.org. For those of you who do not know, phpWomen is a great initiative to bind the girls of the trade together in a sort of community or usergroup. It has received quite a bit of attention lately and in my opinion rightly so!

I have participated in the contest and am actually a bit ashamed that I have only blogged this late about it. I have been busy writing my own entries and reading that of others. I hope that authors will continue to write pieces on the forum. I know I will be there and talk as long as there is something to talk about!

phpWomen does allow men to post on their forum, so you do not have an excuse to pass by and say hello and even add some of your knowledge to the whole.

No Comments »

Kubuntu and a slow Eclipse

Jul 02
Posted on July 2nd, 2008 In category Development 
By mvriel Tagged as Eclipse  Kubuntu 

You know you want to do it, the move, from windows to Linux when developing locally. It works like a charm, except for Eclipse when you do not pay attention.

One could wonder, why do you want to develop locally? Well, sometimes (twice a day) I travel by train. And sitting still is very hard for me (tend to get bored easily) and thus I wanted to be able to do some work in that time. When you do not have a 24×7 UMTS high speed internet connection (or alike) you just have to do it sometimes.

This is where Linux plays an important part, in linux you can simulate your production environment as closely as possible to make deployments and or exchanges as painless as possible. Unfortunately Eclipse tends to grind to a halt when you want to do anything more complicated then typing. Fortunately, there is a fix!

First of all, install Eclipse (I advise the downloadable version with PDT included because the Aptitude version of Eclipse is one number behind (3.2) and PDT 1.x won’t run on it (hasn’t got WST 2.0.0 or higher). When done, get the Java Sun 6 package from Aptitude with the following command: sudo apt-get install sun-java6-bin sun-java6-jdk sun-java6-jre Did it? Good!

Unfortunately Linux might not understand you actually want this to be your default JVM so you need to edit /etc/jvm and type the path where your JRE is installed at the top of the list (usually this is /usr/lib/jvm/java-6-sun sudo nano /etc/jvm In some case Eclipse does not dig it either (annoying, is it not?) and you can force Eclipse as well to use your new Sun JVM by placing the path in the /etc/eclipse/java_home file (or wherever your eclipse installation path is) sudo nano /etc/eclipse/java_home Last but not least: tell your linux version to use this JVM with the following command: sudo update-java-alternatives --set java-6-sun After this, your eclipse (and other Java applications) will work like never before!!

No Comments »

Errorhandling in PHP, now with Fatal Errors included

May 16
Posted on May 16th, 2008 In category Development 
By mvriel Tagged as Error Handling  Fatal Errors  PHP  Singleton 

Every once in a while you stumble upon a topic that you thought would have been completely covered. This I thought as well about PHP Errorhandling. Although resources are abundant about the topic, most of them cover Error handling without handling the Fatal Errors or with hacks for a solution.

This last problem can easily be solved as I wil explain in this post. We wil build an errorhandling class which starts trapping errors from the moment it comes into existance.

What comes first in such a task is to review what it must do, for this specific class we assume the following:

  • We run PHP 5.2.0 or higher, this is needed for our little trick
  • The class must be a singleton
  • It must trap all possible errors, including fatal errors
  • Once trapped, we can do custom handling with them and then pass the error to the defaulthandler

The class skeleton

Since we have stated as a requirement that our class should be a singleton, we will have to define the constructor as being private and create a getInstance method. The latter will instantiate the class the first time it is called.

Below is an example of how to do a singleton class skeleton:

1
2
3
4
5
6
7
8
9
10
11
class My_ErrorHandler {
  private function __construct() {}
 
  public static function getInstance() {
    static $Instance = null;
    if ($Instance === null) {
      $Instance = new My_ErrorHandler();
    }
    return $Instance;
  }
}

Although this post is not about Singletons in PHP I might as well explain a little about the code above. In our new class we define the constructor as private, which effectively means that we can only instantiate this class from within and not from another class.

Protected would do as well and would perhaps be better because classes which extend this one can also call the constructor, but I leave this open to debate

And to round up we create a static method named getInstance (sounds logical?) which contains a static variable holding the instance. When this method is called we check whether the static variable contains our instance and if it does not, we instantiate is. It really is that simple.

For the sake of completeness I must add that another way is to define our instance variable as a private static class variable instead of a method variable, this has the added advantage that other functions in the class could use it. I personally like to encapsulate it this way.

Errorhandling as you know it

Now that we have the basis for our errorhandling class, let’s create an error handling method as described in the PHP Manual. It is actually quite simple and I will quickly go over it.

All one has to do is define a method and register it to PHP with the set_error_handler call. A method needs to have 5 parameters:

  • An error level, this gives an integer corresponding to the E_ error constants fo PHP, i.e. E_WARNING
  • A message, here we receive the text accompanying the error
  • A file name, this is the file in which the error was triggered
  • A line number, this is the line number where the error occurred
  • An errorcontext, this is an array containing all the variables and their values in the scope where and when the error occurred

Now we can choose, do we fully handle the error ourselves, including handling when to die the script or not? This can be done by the return value of our method. If we return false, the default PHP error handler handles the error. And if you do not specify a return value PHP will believe you handled the complete error and continue executing where it was. I usually return false since I want to catch the errors and do something extra, like send it to the Syslog or sending an e-mail in some cases.

Example:

1
2
3
4
5
6
public function error($level, $message, $file, $line, $ctx){
  if (error_reporting() > 0) {
    // Do something here ...
  }
  return false;
}

You might have noticed that I check whether error_reporting is larger than zero. This is because of the at(@) operator. If we do not check this we end up handling the errors which were supposed to be silenced via the @ command.

To wrap this part up, we insert the set_error_handler call to the constructor of our class. This makes sure that once the class has been instantiated, we immediately start catching errors. By the way, if you intend to send output to for example a Syslog, make sure you tell PHP to give plain text message instead of HTML typed. Should you intend to use assert statements, add ASSERT_WARNING to your assert options.

Another example showing all of the above:

1
2
3
4
5
private function __construct() {
  ini_set('html_errors', '0');
  set_error_handler(array(&$this, 'error'));
  assert_options (ASSERT_WARNING, 0);
}

Catching the fatal error

The above is all fun but well, it still does not catch the dreaded fatal error which let’s your application end up all white. Well, this is what we are going to address now and is actually really simple once you know it (and you run PHP 5.2+, but you do that, right?)

With PHP 5.2.0 a new command was introduced, namely: error_get_last. This function returns the last error which has occurred in PHP. Although it might not sound exciting, try combining it with register_shutdown_function.

If you register a shutdown function which calls error_get_last and checks if an error has occurred, it can call our previously defined error function with the given level, message, file and line. With this call we have automatically caught our fatal errors as well!

Let me show you:

1
2
3
4
5
6
7
function shutdown() {
  $error = error_get_last();
  if ($error != null) {
    $this->error($error['type'], $error['message'], $error['file'], $error['line'], 0);
    exit;
  }
}

And we call the register function in our constructor as well:

1
2
3
4
private function __construct() {
// .. Things we have defined above ..
  register_shutdown_function(array(&$this, 'shutdown'));
}

Conclusion

This is all there is to it, if you call My_Errorhandler::getInstance() at the beginning of your script then all your custom error handling will automatically be invoked. You can use the power of this function to pro-actively handle errors instead of waiting for users to report them to you. Just couple this with your Syslog or auto-mail the development department and you will know when things go bad.

I know I had fun writing this, I hope you have by implementing this!

No Comments »

« Previous Page — Next Page »
| Log in | Icons are part of the Crystal Project and copyright of Everaldo Coelho
Mike van Riel is a Senior Software Developer at Unet BV, an ISP for the corporate segment based in the Netherlands.

With a passion for industry standards and Quality Assurance he loves nothing more than to discuss methods to improve code and ways to 'Do-It-Better'™ in general.

You can contact him by:
mike.vanriel[at]naenius.com
@mvriel
http://www.linkedin.com/in/mvriel
mike.vanriel[at]naenius.com
mike.vanriel[at]naenius.com
mike.vanriel