AMI or AGI?

I have setup a server with asterisk and I need send request or evet to a other server in the same lan when we get a new incomminc call, when answered, when transfered and when terminate the call.

What is the best sollution? AMI or AGI?
Also I will need a callerid popup for all the pc in the lan.
Can you help to find same examples?

I think you best bet here is AMI.

where can i find example how can i triger AMI at this 4 states? (incoming,answered,transfered,terminate)
I build a custom web app with php+jquery.

Which version of Asterisk are you using?

1.8 and 11

Asterisk 11 is a development oriented release, and as such it only has short term support. It maps directly to Asterisk 12, which is a LTS (long term support) product. Porting from 11 to 12 should not be a big deal. The reason I mention this is that in 12, a thing called ARI (Asterisk Restful Interface) is exposed. ARI is a very well crafted interface compared to AMI, especially on 1.8. ARI let’s you build applications with intuitive and thoughtful API calls, but it also exposes events in a tidy fashion. Much much much nicer and cleaner than AMI in my opinion.

That said, if you are not willing to make the jump, AMI works just fine. It’s not too involved…create a TCP socket and listener to AMI, authenticate then go.

EDIT: I reread your original post and had another thought. I could be wrong on this, but when I believe when you have events turned on in AMI, it’s an all or nothing kind of thing. You get LOTS and lots of messages. And if you do not implement your socket/listener code very well, this amount of NOISE (you probably won’t need most of it) can cause issues.

An alternative is to have your third party application implement a simple listener, but to also have a small script/program that can open a socket, write a special code and close. In this way you can just use Shell(…) or System(…) calls in your dialplan only at the few exact places you need them (transfer, incoming call, hangout, etc). You just fire off little messages and your third party application listens, processes them and does stuff. Less traffic, less noise, and no reliance on AMI.

Probably this is all that I need.
I am new with asterisk and I dont know about diaplan.
Can you hellp me with this?

Nobody knows how this is done from the dialplan???