Duration of a call

I’d like to display in my php page or in Asterisk cli which extension is currently calling and the duration of a call in seconds (the best with the remote party number).
Maybe it could be achieved with phpagi?

just look for the currect active channels (e.g. asterisk -rx “core show channels”), gather the channel-names and then look for a specific channel (asterisk -rx "core show channel ").
This may alo be used within any kind of scripting language.

An other - different - approach is using the Asterisk-Manager-Interface for Your goal collecting the events asterisk is throwing while processing calls.

For both ways You should find examples in the net.