Call status

Hi,
How can we get call status from asterisk to a php programme. ie, If an agent is busy how we get the info , bcoz I want to update my database in mysql for the agent that is engaged =True.
Help me…
Thanks in advance
ijb