Archive for May 2008

*AMP and Runaway Scripts

Peter Zaitsev posted a very interesting test on how PHP and Apache handle runaway PHP scripts.

I'm sure all of us have had a long executing SQL script or at least a runaway script, and he points out even with ignore_user_abort set to FALSE and max execution times set both in PHP and Apache, a runaway SQL query can execute beyond the timeouts, even when aborted by the user (stop button on the browser).

Even using the function connection_aborted() to check for a user abort fails.

However, the script will cease on a user abort if it performs regular ob_flush(); flush(); commands. For example:

<?php
echo("Hello");
for($i=0;$i<10000;$i++)
{
	sleep(1);
	echo('.');
	ob_flush();
	flush();
}
?>

Just one more reason why I love the MySql Performance Blog.

CompizFusion: Blur Your Terminal Window!

Messing around with CompizConfig the other day and discovered a nifty tweak: blur your transparent terminal windows!

Blurred Gnome Terminal!

To do this you need CompizConfig installed:

sudo apt-get install compizconfig-settings-manager

Once installed, go to System > Preferences > Advanced Desktop Effects Settings. Scroll down to Effects and enabled Blur Windows. Then click the Blur Windows button to open the configuration panel. Set "Alpha blur windows" to (class=Gnome-terminal), Check Alpha Blur, set "Blur Filter" to Gaussian, and set "Gaussian Radius" to 9.

Settings for Alpha-Blurred gnome-terminal

Automating the Development Workflow

I just rolled out some new automation tools for a few projects here at work and so far I've been extremely happy.

Much to my embarrassment, development has previously been outside of source control due to the fact that we develop sites, we don't deploy packaged applications, and we don't have a cohesive IT setup (everyone sets up their desktop to their liking so maintaining consistent development environments across all computers is difficult).

However, thanks to SVN, Xinc and Phing (and DBDeploy), this has changed! Now everything is in source control and automatically deployed to our dev server upon commit. I am currently talking with Arno about perfecting svn tag monitoring to automate staging and (possibly) live deployments, so I'll post about what I did when that's finished.

The great thing about this setup is all pieces are technically interchangeable. If you don't like Xinc you can use CruiseControl. If you don't like Phing you can use Pake, or a shell script even. If you don't like DBDeploy you can roll your own setup or swap it out for your database versioning system of your choice!

However this post will cover Xinc, Phing, and DBDeploy as (a) I have experience with them and none of the others, and (b) they integrate extremely well (Xinc and Phing's primary distribution method of choice are PEAR channels).

Continue reading ‘Automating the Development Workflow’ »

Indy!!

 
from indiana import jones
import whip
import ruins
 
cave = new Ruins()
 
trap = indiana.steal( cave.treasure )
indiana.escape( trap )
 
ImportError: Snakes? I hate snakes!

Partial Classes in PHP

One of my favorite features of C# is Partial Classes. For the uninitiated, it is a way of defining a class in two separate locations. Very useful when you have code generation utilities such as LINQ.

Unfortunately, PHP has no such feature (though if anyone's listening it would be a great feature to add to the PHP6 feature list), however thanks to the magic of __call($method, $args), __get($key), and __set($key, $value) overload functions as well as passing by reference (aah the good ol' &) we can imitate partial classes.

The idea behind this partial class hack is to instance a copy of the partial class in question and have our magic functions forward any undefined requests to the partial class.

The partial class (probably with the naming convention Partial_CLASSNAME) will contain a reference to the main class and also have magic functions forwarding undefined requests to the main class. The reason why we have our magic functions in the partial class is so that any internal references can still be made (methods in Partial_CLASSNAME must have access to the methods and members in CLASSNAME).

The constructor in the main class will automatically seek out the partial class (and additional coding can be done to seek out more than 1 partial class as well as do some integrity checking) so that the programmer does not have to intervene to form the 'full class'.

Continue reading ‘Partial Classes in PHP’ »