|
Sunday, March 4. 2012
Introduction
This document explains some best practices for application error/debug logging. Application logging is an important "tool" to help identifying problems. If done correctly, and if an infrastructure is in place that allows events to be put into context, it's easier to debug situations and thus makes it easier to solve problems sooner.
While out of scope for this document, I'd like to point out the following tools that can make that possible:
Different logging meanings
Logging can mean different things and logging can have different purposes. The logging this document refers to is application and semantic logging.
Application logging (also called "debug" or "error" logging) is intended to keep track of the "low level" application behaviour. Application logging is used to log events, that allows for debugging a problem within an application or to monitor application health. In contrast, a different form of logging could for example be Google Analytics. Tracking (or "logging" actions of) visitors of a website, this type of logging is very different and not something this document refers too.
Why do we log
In order to understand how to log, it must first be clear what we try to accomplish with application logging.
Continue reading "Logging best practices"
Tuesday, November 2. 2010
It has been a while, but here is part 4 of the PHP Quiz series! A few questions to crack your brain about, or perhaps you know them all? Try them and find out! Also do read the idea behind these quizzes, here: The PHP Quiz series
As always, think of the answer before you execute the code or look it up. Codepad might help you run the examples. You can find round three here. Visibility is keyNow you see me, now you don't class testClass { private $fubar = "rabuf"; function test ($test) { var_dump($test->fubar ); }}class dummy { function test ($test) { var_dump($test->fubar ); }}$object1 = new testClass; $object2 = new testClass; $dummy = new dummy; $object1->test ($object1); // Can $object1 see the private property of object1 ?$object1->test ($object2); // Can $object1 see the private property of object2 ?$dummy->test ($object1); // Can $dummy see the private property of object1 ? Static, sticky, ickyclass test { public $counter = - 1; public function increment () { static $cnt = 0; $this->counter = ++ $cnt; return $this; }}$object1 = new test; $object1->increment ()->increment (); $object2 = new test; // What will the output beecho $object2->increment ()->counter; Getting the classclass b { function getClassA () { echo get_class($this); } function getClassB () { echo get_class(); } function getClassC () { echo __CLASS__; }}class a extends b {}$a = new a; // What will be returned, 'a' or 'b' ?$a->getClassA (); $a->getClassB (); $a->getClassC (); The strptime function$result = strptime ('2010-11-28', '%Y-%m-%d'); // What is the output?echo $result['tm_mday'] . '-'. $result['tm_mon'] . '-'. $result['tm_year']; The oldtimerfor ($i = 0, $loop = 10, $a = 10; $i < $loop; ++ $i, $a = 0) { ++ $a; }// What is the output ?echo $a;
Tuesday, June 8. 2010
You get NULL! Well you get NULL when you don't cast. Say for example you do the following: $dbh = new PDO ([.. ]); $stmt = $dbh->prepare ('SELECT accountid FROM dbo.Account'); $stmt->execute (); echo $stmt->fetchColumn (); // NULL
But when you do the following: $stmt = $dbh->prepare ('SELECT CAST(accountid AS varchar(36)) accountid FROM dbo.Account'); $stmt->execute (); echo $stmt->fetchColumn (); // "F05C92A1-3119-4206-A123-49A759AC99FB" I didn't think the casting would be necessary, since according to the manual: http://msdn.microsoft.com/en-us/library/aa226054(SQL.80).aspx the datatype 'uniqueidentifier' has implicit casts with multiple data-types. But I guess it's just one of those things...
Friday, June 4. 2010
I was asked to create a web interface front-end with Microsoft Dynamics CRM as back-end. But I had some troubles setting up the connection, since it has to be done using a domain logon. This doesn't have to be a problem at all, unless your configuration is wrong! In this article I'll explain a few things and point you in the right direction when you have login problems.
As stated earlier, the server running the PHP installation is not Microsoft. In this case a AS400 installation, but it could've been a Linux installation also. I'm using PDO for this article and PHP version 5.2.11. Even if you don't want to use PDO, I recommend using it only for debugging (if possible) since that will give you *most likely* more debug information then the mssql_* family.
When using PDO with a MS-SQL database, you'll need to supply "dblib" as driver and DBLib uses FreeTDS as underlaying library. FreeTDS can be a source of troubles when you're trying to connect, if not configured properly. So I'll kick-off with a little information about it. Don't skip it if you have login problems!
Continue reading "Connecting from PHP on a non Microsoft OS to MSSQL with a domain account"
Tuesday, November 3. 2009
IntroductionThis is a blog about running two PHP versions on one webserver and using multiple php.ini files, this combination can be a tricky one to tackle. But luckily one we can tackle quite easily as long as one of the PHP versions is >= 5.2.7. For this example I'll be using Apache, but the webserver flavor doesn't really matter. The most important part is the "PHP_INI_SCAN_DIR" environment variable. The whyThere could be a number of reasons to want what I'm about to talk about. In my case I have a project where I have a legacy code-base, running on a specific PHP version, and a new code-base which will be run on 5.3. Because the new code-base will be a ongoing progress of replacing the old, it first has to run side by side with the legacy code-base. So I wanted my development image to run two PHP versions. The old code-base used php.ini settings such as a include-path, error reporting, etc. Which will be different from the new code-bas, and those can no-longer be set with the 'php_value' feature of Apaches since the PHP version we'll be using for that runs as (f)CGI rather then as module.
Continue reading "Multiple PHP versions on one webserver"
Sunday, October 11. 2009
Recently I got asked if I knew about a system that supports multiple session back-ends at once. I didn't know about one and since it's not rocket-science I decided to spent a few hours and whoop something up. For the impatient, checkout: http://github.com/Dynom/SessionHandler What does it do?It is a drop-in high-availability storage back-end for PHP sessions by offering a redundant session storage system. It's as easy as including the lib, define the drivers you want to use (e.g. Memcache and MySQL) prepare their configuration/installation and done. If you already have a MySQL server and a Memcache instance running you can set it up in about 5 minutes. It's also easy to extend and write new drivers, just extend the template class and fill in the blanks.
Continue reading "Multiple backend session storage handler"
Monday, September 21. 2009
Welcome to another part of the PHP Quiz series, again some interesting questions to crack your brain about. If you have some nice additions or questions, be sure to leave a comment. Enjoy part three! As always, think of the answer before you execute the code or look it up. You can find round two here. Unset castWhat is the type of $a and what is the type of $b
Form funWhat will the output be? <form method= "post" action= "" enctype= "text/plain"> <input name= "search" type= "text"> <input type= "submit"> </form> <?php error_reporting( E_ALL ); echo (string ) filter_input (INPUT_POST, 'search'); ?>
Fun with stringsStrings in PHP are versatile, but how versatile are they... What will the output be? $juggling = "Itffkhmf"; $rox = "Spy"; $b = $c = ""; for ($i= 0; $i<strlen ($juggling); $i++ ) { $b .= $juggling[ $i ]; $b++; } for ($i= 0; $i<strlen ($rox); $i++ ) { $c .= $rox[ $i ]; $c--; }var_dump( $b, $c );
Continue reading "PHP Quiz part 3"
Thursday, June 25. 2009
In these blog series I'd like to talk a bit about some "Did you knows". These series contain information I came across along the way and I mention them here to give you insight or just to make you aware of it's existence. The information is by no means in chronological order and mostly not even covering "state of the art" or "brand new" items for that matter. Some are directly code related, others are just brief descriptions. Basically it's just a pile of PHP and web related information. You can find part one here.
Continue reading "Did you know... part two"
Thursday, May 14. 2009
A short quiz this time, but that doesn't make it less fun. Do you know the answer to all of them? Get a cup of coffee and kill 10 minutes with round two...
As always, think of the answer before you execute the code or look it up. You can find round one here.
Array pointerWhat will the output be ?
$array = range(0, 5); next($array); foreach($array as $v) { echo $v; }
ArrayAccess and isset fun isset or not isset, thats the question.
Typo?The output might be confusing..
ReferencesHow many notices will be thrown?
error_reporting(E_ALL); function a ( & $array) {} function b ($array) {}a ($array); b ($array);
Continue reading "PHP Quiz part 2"
Wednesday, April 15. 2009
Here a few of those "how did that work again" things, in Zend framework. Mostly for myself but hey, I'm not greedy. If you know some new/nifty ones, feel free to leave a comment! Loading a view from a different directorypublic function someAction () { // Option one $titleView = new Zend_View (); $titleView->setScriptPath ( APPLICATION_PATH . 'views/scripts/'); // Option two $titleView = new Zend_View (array('scriptPath'=>APPLICATION_PATH . 'views/scripts/')); $viewResult = $titleView->render ('_my_view_script.phtml'); }
Continue reading "Zend framework reminders"
|