PyCmd & Console2 – Windows command prompt reloaded

Finally! A command prompt for Windows that doesn’t suck! Now the Linux guys have no reason to smile at (the) Windows (console) anymore.

http://sourceforge.net/projects/pycmd

It offers you a searchable(!) command history(!) and surely some other cool stuff, but I stopped reading at this point and directly installed it right away.

It integrates nicely with

http://sourceforge.net/projects/console/

which amongst other kick ass features allows multi tabs(!) and a not-totally-weird-and-counter-intuitive way to Copy & Paste text. Nice.

Just go to Settings > Console and select the PyCmd executable for “Shell”. If you want to define different tabs go to Settings > Tabs. This way you can also integrate MINGW32, the Linux bash emulator for Windows that comes shipped with Git for Windows.

Ultimate command prompt power unleashed. Sort of.

Absolute Beginner’s Guide to Node.js

To be honest, when I first read the NodeJS website I was like “Ok. WTF?”. I didn’t really understand the complete picture, and it seems I wasn’t the only one.

An Absolute Beginner’s Guide to Node.js by Brandon Cannaday is ought to bring relief for our poor souls. It’s short and concise, and after reading it you can keep on agreeing on that Node.js is some cool stuff without having that specific itch behind your forehead.

URL ViewHelper and Child Routes in ZF2

Given this route configuration for a module

  'router' => array(
        'routes' => array(
            'test' => array(
                'type'    => 'Literal',
                'options' => array(
                    'route'    => '/test',
                    'defaults' => array(
                        '__NAMESPACE__' => 'Test\Controller',
                        'controller'    => 'Index',
                        'action'        => 'index',
                    ),
                ),
                'may_terminate' => true,
                'child_routes' => array(
                    'default' => array(
                        'type'    => 'Segment',
                        'options' => array(
                            'route'    => '/[:controller[/:action]]',
                            'constraints' => array(
                                'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                'action'     => '[a-zA-Z][a-zA-Z0-9_-]*',
                            ),
                            'defaults' => array(
                            ),
                        ),
                    ),
                ),
            ),
        ),
    ),

I wanted to create an URL using the ViewHelper which directly links to an action of the Index Controller, e.g.

/test/index/my-action

To achieve this, it is important (and not so obvious, maybe) to append the name of the child route to the name of the parent route separated with a slash, e.g.

echo $this->url(
          'test/default', 
          array('action' => 'my-action', 'controller' => 'index')
        );

otherwise the helper won’t care about the child route and only link to /test. Tricky…

Neor Profile SQL

Recently I discovered a free and easy to use SQL Profiler for Windows, Mac and Linux:

www.profilesql.com

It works as proxy between the Application and MySQL itself, so basically all you need to do is configuring your Application to use it by simply adding the port number 4040 to the host (and configure the Proxy to connect to MySQL, of course).

As inherent to the functional principle of a Proxy, the Profiler has to be running – so don’t forget to remove the port from the host when you don’t need it.

Getting the subclass name in the parent class

A mistake that I keep making – I have a class that extends another class, and I need to know the class name of that subclass. However the function where I need the name is in the parent class. In this case the magic constant __CLASS__ won’t work, as it will return the name of the class where it is found. get_class() won’t work, too. Not without an important difference:

abstract class Foo
{
   public function getClassName()
   {
      return __CLASS__;
     // or return get_class();
   }

   public function getSubClassName()
   {
      return get_class($this); // the reference $this is important here
   }
}

class Bar extends Foo {};

$bar = new Bar();

echo '1. ' . $bar->getClassName();
echo '<br>';
echo '2. ' . $bar->getSubClassName();

This will result in

1. Foo
2. Bar

The first function call returns the (in my case) incorrect name of the parent class, while the 2nd function works as I need it.

Updating XAMPP without a headache

After some years the time has come to update my local WAMP stack to a more recent PHP version. I also made good experiences with WAMP (the other cool stack for Windows), but I’ll stick with XAMPP and install 1.8.2. This will also make things easier.

  1. Rename the old xampp installation directory C:\xampp (or where you installed it) to C:\_xampp
  2. Install new XAMPP under C:\xampp
  3. Copy all (needed) files/projects from C:\_xampp\htdocs to C:\xampp\htdocs
  4. Copy all (needed) databases from C:\_xampp\mysql\data to C:\xampp\mysql\data. EDIT: Don’t do that if your databases contain InnoDB tables. Use mysqldump instead.
  5. Check differences between both php.ini files, located in C:\xampp\php
  6. If you made changes on your MySQL configuration, don’t forget to check C:\xampp\mysql\bin\my.ini as well
  7. check your PHP Extensions in php/ext: you will need new versions of any additional PHP extensions (e.g. libpdf). Keep in mind that PHP 5.4 has been compiled using VC9 instead VC6 as in PHP 5.3 when chasing for downloads!
  8. Take over changes in C:\xampp\apache\conf\httpd.conf – most likely you’ll have some VirtualHost configurations
  9. Run the security check in XAMPP (http://localhost/security/index.php) to set the MySQL password to the same password you used in the old XAMPP installation (if you’re using a password)
  10. Be happy! You now shouldn’t need to change any path configurations, passwords etc. to run your web applications on your new PHP 5.4 stack!

The actual migration from PHP 5.3 to 5.4 shouldn’t be a problem, as there aren’t that many compatibility issues. I didn’t experience any PHP issues so far.

I was rather concerned about just copying the MySQL files – but it worked like a charm and is definitely quicker than doing mysqldumps and loads on many big databases – UNLESS you don’t have InnoDB tables in your databases. In this case better use mysqldump. In general it’s a good idea to keep an eye on the mysql_error.log in the data directory.

Good thing about this approach: you still have your old XAMPP installation at hand which you can reuse by simply renaming the two directories. Always be backed up!

Second chance – Old notebook refurbished

My 5 or 6 year HP Compaq 6910p still is in good shape. Back in the days it was a very decent business machine and served me well many years. Surely it is not comparable to a top notch notebook anymore, but totally ok for easy development or browsing.

However the Windows XP installation wasn’t bearable anymore, took ages to load and as we all know it won’t be supported from next year on. The hard drive was very slow and already made strange noises sometimes.

So I decided to give my old pal a second chance and ordered

  1. Windows 7 Pro for 30 € (erm … not sure if this is really legal … a DVD with a worn license sticker labeled with “Dell” from eBay)
  2. A new hard drive for 40 €
  3. A new battery pack (Cheap China copy) 25 €
  4. Pressure air for cleaning the fan 6 €

The new hard drive performs way better (at least that’s my impression, I didn’t benchmark it), and the fresh Windows 7 installation loads really fast again! The new battery doesn’t even run half the time the old used to do, but I don’t expect long train rides in the next months. So as a roundup:

  • Investment: 101 €
  • Fun factor: As much fun as installing dozens of tools can be
  • Environmental aspect: I guess one Notebook minus a hard drive and a battery pack
  • Result: totally worth it!

PHP mail() on Windows

Setting up an email server on Windows can be a real pain. Hardly worth the effort when all I want to do is using PHP’s mail() function.

I found a nice workaround when I updated my XAMPP installation: http://glob.com.au/sendmail/. All you need is an SMTP server somewhere that you can use, because sendmail.exe will just forward the emails to it.

You still need to configure it though:

  1. Configure your SMTP in the sendmail.ini (located usually under C:\xampp\sendmail)
  2. In the php.ini, ensure you have the following set up
    [mail function]
    sendmail_from=your@email.de
    sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

That’s it. Now you can quickly test it (below script more or less stolen from php.net):

$name = "Sender"; 
$recipient = "your@email.de"; 
$email = "recipients@email.de"; 
$mail_body = "The text for the mail...";
$subject = "Subject for reviever";
$header = "From: ". $name . " &lt;" . $email . "&gt;\r\n";

mail($recipient, $subject, $mail_body, $header);

If everything is set up correctly, you should notice that the execution of the script takes a moment. If it runs through fast, something did not work – or you have a really fast machine & connection.

Note: although I had some config errors the first time the error.log in the sendmail directory was not populated with any messages. I don’t know when this file will actually be used.

Create your own PHP extension (on Windows)

Have you ever thought about writing your own PHP extension? There are surely a few pro’s and con’s about creating PHP extensions to solve problems, rather than write PHP libraries. But this is not the question here. I was curious. So come on Internet, let’s see what you got for me…

http://www.dreamincode.net/forums/topic/244215-introduction-to-creating-a-php-extension-for-windows/

http://blog.slickedit.com/2007/09/creating-a-php-5-extension-with-visual-c-2005/comment-page-2/

Looks a bit outdated, but that’s not the problem here for me. As a matter of fact, I’m currently still using PHP 5.3.5 on my dev for a list of reasons. And I’m using Windows and I don’t complain (I know my colleagues think I’m weird). Luckily both tutorials cover the topic on how to create the extension on Windows for PHP 5.3.5. So much win! And the best: it really works!

Basically both tutorials provide you with everything you need. I had to get over two pitfalls though:

  1. php5ts.lib is not in the source code directory I just extracted, but in my WAMP stack already – in my case I located it in C:\xampp\php\dev
  2. error C2371: ‘socklen_t’ : redefinition; different basic types – I really have no idea why this error came up during compilation. However I was able to “solve” *cough* the problem by commenting out lines 149 to 151 in the php.h:
    #ifndef HAVE_SOCKLEN_T
    typedef unsigned int socklen_t;
    #endif
    

    Surely not the ideal solution, but as I just wanted to try it out I don’t mind at the moment.

Microformats – control what Google shows on the Search Results page

Yesterday I learned about “Microformats“. Microwhat? Sounds suspicious!

Well, at least that was my reaction. I’ve to admit that I don’t care much about SEO and Google and so on (I’m a PHP backend developer, Goddamit!), but this is really interesting topic one should at least have heard of. In short, it allows you to have influence on what is displayed on the Google results page. Worth its weight in Gold, I guess. Some of the ancients amongst us might remember the good old Metatags. It’s not the same, though.

So here’s a link that explains Microformats pretty well:
http://www.dotcult.com/seo-guide-to-microformats