Subscribe to RSS Subscribe to Comments

Alan Blaine Whitney

PHP Oddity

This was tested on PHP 5.2.6 and 5.2.10, you mileage may actually vary.

 <?php
$number = 20864.01;
$num = $number * 100;
echo intval($num);
?>

If such a piece of code was ran, but would one expect, 2086401 maybe. I would, but you actually get 2086400. Strange.

<?php
$number = 20864.01;
$num = $number * 100;
echo intval(round($num));
?>

That will give you 2086401.

UPDATE: I guess this problem is not a PHP per se but a glibc issue.

Debian Etch to Lenny Migration

At my place of employment, sephone internet solutions, we just finished our debian upgrades. Overall I have huge respect for debian and the apt package tool. Overall the migration from etch to lenny across several servers was easy, except for one back.

One server required the bnx2 firmware for a Broadcom NetXtreme II NIC. For one reason or another, the bnx2 driver was not found after doing a standard debian upgrade. This was quite a problem. After apt finished with what looked like a flawless upgraded, I rebooted the box and it had no network interfaces.

After messing with udev and dmesgs for a while, I was able to find this in a log file

Feb 15 14:29:34 sentry kernel: [ 1856.770927] Broadcom NetXtreme II Gigabit Ethernet Driver bnx2 v1.7.5 (April 29, 2008)
Feb 15 14:29:35 sentry kernel: [ 1857.257121] firmware: requesting bnx2-06-4.0.5.fw
Feb 15 14:29:35 sentry kernel: [ 1857.450033] bnx2: Cant load firmware file bnx2-06-4.0.5.fw
Feb 15 14:29:35 sentry kernel: [ 1857.450033] bnx2: probe of 0000:05:00.0 failed with error -2
Feb 15 14:29:35 sentry kernel: [ 1857.833817] firmware: requesting bnx2-06-4.0.5.fw
Feb 15 14:29:35 sentry kernel: [ 1858.185818] bnx2: Cant load firmware file bnx2-06-4.0.5.fw
Feb 15 14:29:35 sentry kernel: [ 1858.185818] bnx2: probe of 0000:09:00.0 failed with error -2

After finding that, I asked a co-worker to manual download the package through a browser on a different machine, put it on a CD, and manually place the file as /lib/firmware/bnx2-06-4.0.5.fw.

With the file now there I needed to try to reload that module

modprobe -r bnx2
modprobe bnx2
/etc/init.d/networking restart

Lo and behold, I now had network. With the network working, I wanted to install the proper debian package: firmware-bnx2, which is found in non-free, which I already had in /etc/apt/sources.list, but first, I needed to get rid of the file I put in there, in case it messed anything

rm /lib/firmware/bnx2-06-4.0.5.fw
apt-get install firmware-bnx2

I rebooted to make sure that it was going to work. Later it came to me that there was a much simpler solution to this problem, reboot, and in the grub menu, pick the etch kernel, it should boot with network, install firmware-bnx2 and reboot to the new kernel. I had not thought of that until later though.

Cakephp Caching

Recently I was working on an application that needed to have many instances.  That is, one code base in one place that served several sites.  These sites have seperate dbs, seperate configs, seperate views, seperate caches per domain.

So I needed these seperate configs for various sites.  I found this article on the bakery, that seemed to be a good start for me.  That got me so that I had a seperate config file (including db) for my different sites.

While I had seperate configs for each domain, I took the chance to set up cake themes.  So in my config this in my domain config

Configure::write('theme', 'client');

and then I set that in my app_controller in beforeFilter

$theme = Configure::read('theme');
if (isset($theme) && strlen($theme)) {
  $this->view = 'theme';
  $this->theme = $theme;
}

This will get my app so I have separate views inside of app/views/themed/client/layouts/default.ctp and so on.

This worked pretty good, but there was a problem, view caching and db caching was shared across the various sites.  Well, cake puts all of it’s writable stuff in /app/tmp and what I wanted to do was move all of that stuff into per domain directories.  I decided on my systems tmp directory, which on Linux is /tmp, so I made several directories within that one.

/tmp/broadcaster
/tmp/broadcaster/<client-name>
/tmp/broadcaster/<client-name>/cache
/tmp/broadcaster/<client-name>/cache/views
/tmp/broadcaster/<client-name>/cache/persistent
/tmp/broadcaster/<client-name>/cache/models
/tmp/broadcaster/<client-name>/logs
/tmp/broadcaster/<client-name>/sessions
/tmp/broadcaster/<client-name>/tests

So more of less, what I have here is a copy of of app/tmp for every domain.  Now we need to tell cake to use these directories.

Here is my chances in app/webroot/index.php,  right after app_dir.

define('TMP', '/tmp/broadcaster/' . $_SERVER['SERVER_NAME'] . '/');

Here is the bottom of my app/config/core.php

Cache::config('default',
  array(
    'engine' => 'File',
    'prefix' => 'cake_',
    'path' => TMP . '/cache/',
  )
);

So that’s a rough over view of per domain stuff in cake.

Cake 1.2RC3 to Final

Recently the cake 1.2 has been released.  On several of my applications I have upgrading all along the 1.2 release cycle.  Here are my tweaks that I needed to do from RC3 to 1.2 Final.

To start the upgrade, I simply swapped out my cake directory for the new one.  Dropped the tmp dir with this command.

find app/tmp/ -name ‘cake*’ | xargs rm

For the most part it worked right off the back.  The only problem I had was to switch some things in my “app/app_controller.php”.  In RC3, if it was an ajax request, it automatically switched to an ajax layout.  It stopped doing that in RC4 and final.  So I when to put functionality back in.

To start I added the request handler component and use beforeFilter().

	var $components = array('RequestHandler');
 
	function beforeFilter() {
		if ($this->RequestHandler->isAjax()) {
			$this->layout='ajax';
		}
    }

I actually had several things happening in my ‘app/app_controller.php’ already, here is my actual file.

	var $components = array('Auth', 'Email', 'RequestHandler');
 
	function beforeFilter() {
        $this->Auth->fields = array('username'=>'username', 'password' => 'password');
		$this->Auth->loginAction = array('admin' => false, 'controller' => 'users', 'action' => 'login');
		$this->Auth->allow('*');
 
		$this->set('navPoint', 'home');
 
		if (isset($this->params['admin'])) { 
			$this->layout='admin';
			$this->Auth->deny('*');
 
			// Lets set the sort order
			if (!$this->Session->check('sort')) {
				$this->Session->write('sort', 'Application.date_created DESC');
			}
		}
 
		if ($this->RequestHandler->isAjax()) { 
			$this->layout='ajax';
		}
    }

Notes on the process of Web Development

This post is mostly for me, since I have don’t anywhere convenient to put these notes.

Features

Every feature that gets implemented has to have solid answers to these questions

  1. Why are we doing this
  2. What problem does this solve
  3. Is it useful
  4. Are we adding value
  5. Will this change user behavior
  6. Is there an easier way

Time Limits

Every phase/version/release of a project needs a time limit, say like two weeks.  The question would be, in two weeks will I have something to show for this.  If the answer is no, split your release/version/feature in half and ask yourself again.

Stop Words

Words like need, can’t, quick, easy, everyone, nobody, simple, little, and big don’t need to used.

Focus

The focus sometimes needs to change.  Don’t spend so much time focusing on the hard stuff, but more time on polishing the easy stuff.  Trends are cool, but become too trendy to lose focus on unchanging things.  Optimize for today, tomorrow has enough worries of it’s own.  You can always do it different later.

Interruptions are the mortal enemy

Avoid interruptions at all cost.  A focused man can do more in an hour, than an unfocused man in four.  Use more passive collaboration tools, like wiki’s, project management web tools, internal blogs, etc.

How to add subversion revision into cake template

This post is a quick explaination on how to add a subversion revision number into a cakephp template.  First off you need to tell subversion to place the version into the file.

svn propset svn:keywords “Revision” app/views/layouts/admin.ctp

In this case I am going to add to my admin layout. Now to edit the admin layout.  I am going to add the following line text.

$Revision: $

This will get replaced at every commit/update with

$Revision: 357 $

with the current revision number.

To pull it all together to show the version number. Here is piece of admin.ctp

<?php
$svn = ‘$Revision: $’;
$revision = substr($svn, 11);
$version = intval(substr($revision, 0, strlen($revision) – 2))
?>
(Revision <?=$version?>)

Which will display the current version number.

Cake 1.2RC2 to 1.2RC3

I recently updated a web app from RC2 to RC3.  I replaced the cake dir and replace app/webroot/index.php and app/webroot/test.php.  Deleted my cache files.  Everything went super.  Not one hitch.

UUID’s

I read a good post over at debuggable just now, about UUIDs.  One of the things about the article that struck me that I didn’t know, is that if you have a char(36) field, cake will just start to use them, auto-magically.

This means that in real world application effort wise, auto incrementing ints, or UUIDs are both super easy to use in cake.  Nearly no difference other than your table creation.

This got me thinking about which one is better.  Well, the url’s look better as ints, say ‘/applications/view/147′ versus ‘/applications/view/48c907b0-f088-44ae-8be5-4e811030b5da’.  One is way shorter as well.

Some people quote SEO has being a disadvantage to UUIDs.  I don’t know about that.  It would seem to be that they could be about equal, if both given the same treatment, like putting title in the address.  I would assume that they are equal, but I am not quite sure about this.

The main advantage of UUIDs is uniqueness.  I can see why true uniqueness would be cool.  No centralized system, but yet you have a unique Id.   Merging tables because easy, makes url hacks harder.

So for me the equation is uniqueness versus easier urls.

I am not a fan of Email

I will try to not let my bias not persuade me too much, but I don’t really like email much.  It is so slow to digest the information contained, so many emails don’t have good content, or are spam, or are forwards, yucky.

Yet, email was once a breakthrough in silent, speedy, low-cost communication technology that so seamlessly fits into the information worker’s day.  Today other technologies are better at the silent, speedy, seamlessly, low-cost information exchange, like Atom, wiki, social bookmarking and RSS. Consequently many experts are saying email cost the economy about 650 billion in lost time, actually some say quiet more than that.

A cnet article quoting Carl Honore research, concluded that the average office worker is interrupted every three minutes (email, IM, phone, other office distractions) and that it takes eight minutes to recover.  So that means very little is being done in the untied states, especially when compared to nations like Japan, India, and a host of others.  The cnet article also concluded that companies are coming up with simple ways, custom software, unique project management and sometimes non-technical ways to tackle the information management issues of this phase of the information age.

Furthormore, PC World publish a comical, but serious article about having email addiction and steps to help defend and wart off addiction.  Appearly some 11 million people, doctors have labeled as having some type of health recking email habits.

Way am I writing this post, other than because I don’t like email.  Well largely it’s due to one factor in my life, which is, I now realize time is constantly working against me, time is not my ally.  Here at Sephone, always working to try to squeak out more,  also I’m writing an application with a friend outside of work, teaching a class that requires hours of study a week, and I am always looking for more time to spend with my wife.  Just seems like time is a continuous opponent, that needs to be properly rendered, or it because evil.

Okay, I think I am really going to make a point, I am working my way to it.  My point is this, time is precious, both at work and elsewhere.  Things like email are great tools, just make sure that you have control over the tools, and your tools don’t have control over you.  If you instance have read an email as soon as you get it, you are a slave to your inbox.  If you often purposely look at your email while you are in the middle of something else, you are a slave to your inbox.  Just encouraging everybody to think outside of the inbox.  By just checking your email every so often then closing your email program, it might surprise you how much time you have in the day.

Pay for Content

Their are some really good web applications out there, but in my life their still are some paper publishications that I have that no web app comes close to replacing.  Some of these are the AMC River Guide and the Delorme A&G.  The amount of detail, both in map data and text is far better than those found online.  With the case of the AMC River Guide, the trips that are detailed were actually taken by the authors.

This got me thinking about a larger scale issue.  In this era of “web 2.0″ and wiki’s and blogs, what will happen to detailed research.  Anyone who has ever done any large research knows that wikipedia may be looked at, but is not a great source of in-depth information.  Any information that may actually be there, is really a citation from something else anyway.

I just wonder what will happen to high quanlity content, that needs to be funded.

Next Page »

Based on FluidityTheme Redesigned by Kaushal Sheth Sponsored by Send Flowers