The good news is: I'm on vacation! Yay

Well, actually vacation is almost over... I have until Wednesday to become totally relaxed and yet there's so much left to do... need to toss out lots of old stuff, scratch the rust off an old Singer sawing machine rack to refit it as a table and things like that. At least in some respect my vacation has been a little bit productive - since last Wednesday I am now officially a Zend Certified Engineer (most probably the last one to ever do the PHP4 certification... well, I still had this voucher that would have gone void on August 31st - guess when the PHP5 certification is due to hit the road...).
Of course, I also wanted to do lots of coding during my vacation - what better method to relax than a good few thousand lines of code, huh? No, I have no life... or do I?

Anyway, the coding part was kind of put back when I hit a very nasty bug that I couldn't find yet. Worst of all, I have no idea if it's the stuff I wrote (more likely), parts of the Zend Framework (ruled out already), PHP itself (less likely) or Apache (likeliness hits rock bottom).
In the unlikely case you should be interested in my pain, read on (this is a lenghty and rather uninteresting one - you have been warned!!).
A while ago, I wrote this ActiveRecord implementation called
CWAC_ActiveRecord to satisfy my need for a high-performance and easy-to-use ORM layer directly on top of PDO that I could use in my Zend Framework powered applications. It's the first package I ever wrote using a test driven development approach, and all unit tests are working okay. Thus I thought to have coded a pretty well-working and seemingly stable thing.
I also wrote
an extension of the Zend_Controller_Action class to satisfy my need for auto-templating. After some small difficulties and finally
tossing the "output on destructor call"-approach, this worked extremely well, too.
To put this to the test, I wrote a very small controller script for the Zend Framework containing an action that would display the form and, if the form data validated okay, insert a new record (user account) into the database and then redirect to a welcome page.
Here's the action method:
public function createAccountAction()
{
$this->_applicationView->title = 'Create a new account';
$post = new Zend_Filter_Input($_POST);
$values =
array('alias' =>
$post->
getRaw('alias'),
'email' => $post->getRaw('email'),
'pw' => $post->getRaw('pw'),
'pw2' => $post->getRaw('pw2'));
if (!$post->testAlnum('alias')) {
$errors['alias'][] = 'This field may contain only alphanumeric characters (letters and numbers)';
}
if (!$post->testRegex('email', '/^[a-zA-Z]([.]?([[:alnum:]<u>-]+)*)?@([[:alnum:]\-</u>]+\.)+[a-zA-Z]{2,4}$/')) {
$errors['email'][] = 'This is not a valid email address. Please check the spelling.';
}
$pwerror = 'Password must be at least 5 characters long and may contain '.
'only letters, numbers and one or more of the following characters: '.
'_ ! . $ # @ ? -';
if (!$post->testRegex('pw', '/^[A-Z0-9a-z_\.\!\$#@\/\?-]{5,}$/')) {
$errors['pw'][] = $pwerror;
}
if (!$post->testRegex('pw2', '/^[A-Z0-9a-z_\.\!\$#@\/\?-]{5,}$/')) {
$errors['pw2'][] = $pwerror;
}
if ($values['pw'] != $values['pw2']) {
$errors['pw2'][] = 'The passwords do not match. Please try again.';
}
if (count($errors) ==
0) { $user = new Usr_user();
$user->alias = $values['alias'];
$user->email = $values['email'];
$user->pw = $values['pw'];
try {
$stmt = $user->save();
$_SESSION['user'] = $user->toArray();
$this->_redirect('http://dev.local/membership/welcome/');
} catch (Exception $ex) {
echo "<h1>Error</h1><pre>".
$ex->
getMessage().
"</pre>";
}
} else {
$this->_actionView->errors = $errors;
$this->_actionView->values = $values;
$this->render();
}
} else {
$this->render();
}
}
When executing the POST request, this is the result as seen in the Apache error log:
[Sun Aug 20 00:39:19 2006] [notice] child pid 18870 exit signal Segmentation fault (11)
The PHP error log shows nothing wrong:
[20-Aug-2006 00:39:19] Call to createAccountAction
[20-Aug-2006 00:39:19] Creating ActiveRecord object
[20-Aug-2006 00:39:19] Goodbye, and thanks for all the fish!
[20-Aug-2006 00:39:19] Saving...
[20-Aug-2006 00:39:19] Executing statement: INSERT INTO usr_user (alias, pw, email) VALUES (:alias, :pw, :email)
[20-Aug-2006 00:39:19] Preparing new statement
[20-Aug-2006 00:39:19] Executing with bindings: Array
(
[:alias] => bla
[:pw] => 12345
[:email] => hink@honk.de
)
[20-Aug-2006 00:39:19] Unsetting statement object
[20-Aug-2006 00:39:19] Going to redirect...
[20-Aug-2006 00:39:19] Arrived at redirect.
[20-Aug-2006 00:39:19] Done header() call... EXIT!
[20-Aug-2006 00:39:19] PHP shutdown
[20-Aug-2006 00:39:19] Destructing ActiveRecord object.
As can be seen, I've added a few extra error_log() calls in the ActiveRecord class as well as in the redirect() method of the Zend_Controller_Action class, to trace the beast. So it appears as if PHP executes the request without any error and then exits cleanly - but then the Apache dies before sending anything back to the browser (including the desired redirect header).
While trying to track things down, I've only been successful in preventing the Apache crash when commenting out the call to ActiveRecord's save() method. When nothing is written to the database, the crash does not occur. Huh?
Okay, trying to break things down a bit further and taking everything out of the equation beside ActiveRecord:
require_once 'CWAC/ActiveRecord.php';
#### Configuration for CWAC_ActiveRecord
'dsn' => 'mysql:host=localhost;dbname=test',
'user' => 'root',
'password' => null
)
),
'model_path' =>
dirname(<u>_FILE_</u>
).
'../application/models/' );
CWAC_ActiveRecord::setConfig($ARConfig);
class Usr_user extends CWAC_ActiveRecord
{
public $id;
public $alias;
public $pw;
public $first_name;
public $last_name;
public $email;
public $active;
public $created_at;
public $updated_at;
}
$usr = new Usr_user();
$usr->alias = 'bla';
$usr->pw = 'bli';
$usr->email = 'blubb';
$usr->first_name="Klaus";
$usr->last_name="Piepenbrinck";
$usr->save();
header("Location: http://blog.wolff-hamburg.de/");
Points of failure eliminated: CWAC_Controller_Action, all of the Zend Framework, and no data coming in via POST. The script is completely self-contained except for the CWAC_ActiveRecord include. Still, the same behaviour. So it would seem the Apache dislikes my ActiveRecord component for some strange reason.
Even more strange: The crash doesn't happen if the request is the first request after starting Apache. The first request always works, no crashes, all is fine. But on all subsequent requests Apache crashes reliably.
Worst of all, I haven't been able to reproduce this on my public development server (Gentoo) - at least with the small test script, haven't tested with the full Zend Framework environment yet. The problem seems to occur only on my home development box (Ubuntu Dapper, with the latest stable XAMPP providing both Apache and PHP 5.1.4). So now I have no idea if this is really a problem with ActiveRecord that just happens only in specific environments or if the problem is specific to just my environment that's totally f...ed up.
Maybe I should just forget about my local box for now and develop on the Gentoo box to finally get something
done instead of trying to hunt down environment-related esoteric bugs that I'll never find anyway... but still, this bugs me quite a bit.
To sum all this up, in regard to "What I did on my holidays" it can be concluded that I've lived in "Interesting Times" (which, for the adept geek, should be a clear indicator on what I've been reading during my vacation)
Last night I blogged about my frustration with a bug in my ActiveRecord implementation that caused Apache to segfault after calling the save() method (which, strangely enough, never occured on the first request after a fresh Apache restart, but on all sub
Tracked: Aug 21, 02:10