Mounting Folders With Mock

| No Comments | No TrackBacks

I use Mock to build RPMs in a clean chroot'd environment - and it works great! The only problem is the documentation is abysmal. Now, I'm not trying to be one of the people who complains and slags off someone else's project - I'm actually trying to not be that person...  but in this case I'm afraid the criticism is absolutely true.


If you need to use Mock then it seems the only place that has any kind of information is the official website. And if you're not already an expert, then like me I expect you'll find yourself pretty lost (though you won't be lost for long as it's only one page, so you'll move on quite quickly from being lost to being completely stuck).

I was quite happily building RPMs with Mock for a PHP application, but build times were slow as the environment was clean each time Composer was having to download every single one of the dependencies.  Not ideal.  Luckily there's a plugin for Mock (which is enabled by default) called bindmount which allows mounting host folders inside the chroot which can then act as the durable cache folder for Composer.

Brilliant! Indeed, if you can figure out how to use it... Sorry...  I'm trying hard and failing to not be bitchy here, but the only documentation I could find that this feature even existed (after resorting to IRC channels) were two lines of example configuration that comes installed with Mock. I used these...

configopts['pluginconf']['bindmountenable'] = True
configopts['pluginconf']['bindmount_opts']['dirs'].append(('/var/cache/composer/', '/var/cache/composer/' ))

But alas...  watching the builds crawl by it was clear nothing was actually being cached.  But no errors, no clues as to why.  I suspected it was something to do with the permissions of the folder on the host I was mounting into the chroot.  After a lot of trial and error I finally hit upon the solution, here it is...

chmod 2755 /var/cache/composer

Or in my Ansible role

- name: Composer Cache Directory
  file: path=/var/cache/composer state=directory
        owner=jenkins group=mock mode=2775

Then the next time I ran a build I could see the dependencies getting written, and after that the build time was cut by about 70%

Yahoooooooooooooo!

Datomic - The Future of Databases?

| No Comments | No TrackBacks

A talk I gave at Unified Diff on Datomic

Getting Clojure

| No Comments | No TrackBacks

A video of a talk on Clojure I gave at Unified Diff

Restoring Large MySQL Dumps

| No Comments | No TrackBacks

I'm not exactly sure what the problem is here, but when restoring some dumps I have problems which results in the message the server has gone away. This fixes it, log in to another mysql session and enter this:

set global net_buffer_length=1000000;
set global max_allowed_packet=1000000000;

It will magically now work!  

Parallel Processing with PHP

| No Comments | No TrackBacks
Try as you might there's no getting away from PHP's single threaded nature.  But when you're looking to speed up your application there may be obvious advantages to parallelising some of the tasks that you have to perform to generate a page.  Unfortunately there's no safe and easy way to handle this easily out of the box with PHP.

If you've ever tried doing this the solution you considered was using pcntl to fork child processes, and then handle the communication back to the parent process somehow.  But this is not a good idea in an Apache process, not reccomended!

The other solution is to use some kind of job processing server like from the Zend Platform (which I've actually only just found as I was writing this post).  But that seems to cost bucks, so how about trying an open source solution, introducing PTask - a parallel processing library for PHP.


PTask is built on the ZeroMQ brokerless messaging library, and uses a server to control multiple worker processes that can then be used for generic job processing.  You implement your own job processor, which is then instantiated for however many workers you configure the server for - meaning no startup time when jobs come in to be processed.

There is a simple client/server example available in the source, so give it a go and let me know if you find it useful.

iTerm Tab Names

| No Comments | No TrackBacks

I always have multiple iTerm tabs open, and found a neat way to name them easily. Add this to your bash_profile

tab() {
    export PROMPT_COMMAND='echo -ne "\033]0;'$1'\007"';
}

Then in your sessions you can set the tab name so it's clear what's what.

$> tab "some tab name"

Beautiful video

| No Comments | No TrackBacks
Just came across a new video by "The American Dollar" on last.fm.

Multiple PHP Versions with Apache

| No Comments | No TrackBacks
Sometimes you'll find that (for whatever crappy reason, supporting legacy junk apps being the most probable) you need to run multiple version of PHP on your web server.  There are a bunch of different solutions I've found people suggesting (using virtual hosts, running one as a module and one as CGI, etc...) but if you're happy running PHP as CGI then this solution may be simpler for you.

The idea is that we'll set up a "default" version of PHP which will handle all our PHP pages, but then for any particular applications that need other versions we'll handle those differently.

So, first the default setup, open httpd.conf...

ScriptAlias /php-5/ "C:/php/5.3/"
AddType application/x-httpd-php .php
Action application/x-httpd-php "/php-5/php.exe"


Then we'll override this setup for each of our applications that require a specific version of PHP.

ScriptAlias /php-4.4.9/ "C:/php/4.4.9"
<Location /my/old/app>
    Action application/x-httpd-php "/php-4.4.9/php.exe"
</Location>


Easy!  No need to run multiple versions of Apache, or fight with strange configuration.

One thing you'll need to do is copy all of the DLL's from each PHP version into the root directory of that version, and of course have different php.ini's for each one, but I'm not going to go into all that config.

I've only tried this on Windows, but it should work on other platforms to.