Archives for March 2010

Using log4php

A how-to for the excellent log4php:

Rolling daily file
Log error statements into one file, and info statements into another
Send emails

Usage

include_once(’/var/www/example/components/log4php/2.0.0/Logger.php’);

class Example
{
private $logger;

function __construct()
{
$loggerConfig = ‘/var/www/example/config/log4php.xml’;
Logger::configure($loggerConfig);
$this->logger = Logger::getLogger(’example’);
}

public function doSomething()
{
$var = $this->getSomeValue();
$this->logger->debug(’in doSomething: $var = ‘ . $var);
try
{
$this->doSomethingSpecific();
}
catch (Exception $ex)
{
$this->logger->error($ex->getMessage());
throw new Exception(”There is a problem with Something. We apologize for any inconvenience caused.”);
}
$this->logger->info(”doSomething successful”);
}
}

log4php.xml

<log4php:configuration xmlns:log4php=”http://logging.apache.org/log4php/”>
[…]

27 March 2010 | PHP | No Comments

Calling a .NET asmx web service over https from PHP

Enable SOAP by uncommenting “extension=php_soap.dll” in php.ini
https should be included in “Registered PHP Streams” (phpinfo) – uncomment “extension=php_openssl.dll” in php.ini

// SOAP client

$wsdl = ‘https://www.example.com/services/ProductManagement.asmx?wsdl’;
$endpoint = array
(
‘location’ => ‘https://www.example.com/services/ProductManagement.asmx’
);
$soapClient = new SoapClient($wsdl, $endpoint);

// SOAP header

$soapHeaders = array();

$namespace = ‘http://www.example.com/services/ProductManagement’;
$elementName = ‘Authentication’;
$authenticationHeader = array
(
‘Username’ => ‘user9′,
‘Password’ => ‘pass1234′,
);
$soapHeader = new SoapHeader($namespace, $elementName, $authenticationHeader);
$soapHeaders[] = $soapHeader;

$soapClient->__setSoapHeaders($soapHeaders);

// SOAP call

$parameters->productCode […]

26 March 2010 | PHP | No Comments

Data Sanitizer

I wrote a C# console app to sanitize CSV files. It replaces numbers with X’s so that social security number 123456 becomes XXXXXX and the address “49 Main St” becomes “XX Main St”. Both the input and the output are streamed to ensure that the program won’t run out of memory even with arbitrarily large […]

19 March 2010 | C# | 1 Comment

Urgent

You don’t know the meaning of urgent until you’re stuck in a traffic jam with a small child who has just started potty training, who urgently needs to go …

17 March 2010 | Uncategorized | No Comments

App feature request

I wish that desktop apps would have this feature: when I attempt to close it, and it asks, “Do you want to save the changes you made to <filename>?”, there’s an extra button that says “View unsaved changes”.

11 March 2010 | Uncategorized | No Comments

idea rumah