Capture Event: Cdr

Does anyone know if it is possible to capture the Event: Cdr information from the AMI from within an AGI script that gets called on DeadAGI. And if so how. I am using PHP for my AGI script

If i log into the AMI from the command line i can see the cdr information when the call is hungup.

Any clues or pointers will be greatly appreciated

ok, i have found that i can almost achieve what i need by using the following

exten => h,1,DeadAGI(dialHangup.php|${CDR(start)},${CDR(answer)},${CDR(end)},${CDR(duration)},${CDR(billsec)},${CDR(disposition)},${CDR(accountcode)},${CDR(userfield)})

but the end time, duration and billsecs are always null

Any ideas anyone?