How to call PHP Scripts to search details in DB based on caller phone number

Hello @vespino & @lgaetz , first thanks for your help with this, happy to report that I made it to work!!!
The first mistake I was making is in extensions_custom.conf, apparently when you create an extension, it is saved in sip_additional.conf with context=from-internal.
So updated it as follows;

[from-internal-custom]
include => tigapii

[ tigapii]
exten => 701,1,AGI(test.php)
exten => 701,n,NoOp(MANDELA)
exten => 701,n,Set(CALLERID(name)=${lookupcid})
exten => 701,n,Dial(SIP/701,10,t)
exten => 701,n,Hangup()

My test.php script remained the same except the ‘$no’, which i changed to just phone=$no.
Made the script executable and changed it to be owned by asterisk, and that’s it. My script is executed as shown below, and the title, firstname & lastname**[Mr Test2 test2]** are substituted for the callerid[e.g 705] variable when a call is made to extension 701.
Hope this helps any other person.

– Executing [701@from-internal:1] AGI(“SIP/705-00000002”, “test.php”) in new stack
– Launched AGI Script /var/lib/asterisk/agi-bin/test.php
– <SIP/705-00000002>AGI Script test.php completed, returning 0
– Executing [701@from-internal:2] NoOp(“SIP/705-00000002”, “MANDELA”) in new stack
– Executing [701@from-internal:3] Set(“SIP/705-00000002”, “CALLERID(name)=Mr Test2 test2”) in new stack
– Executing [701@from-internal:4] Dial(“SIP/705-00000002”, “SIP/701,10,t”) in new stack
== Using SIP RTP TOS bits 184
== Using SIP RTP CoS mark 5
– Called SIP/701
– SIP/701-00000003 is ringing
> 0x7f1038014710 – Strict RTP learning after remote address set to: 192.168.1.143:8000
– SIP/701-00000003 answered SIP/705-00000002
– Channel SIP/701-00000003 joined ‘simple_bridge’ basic-bridge <12c81c89-9617-4b65-a139-2553d4d34798>
– Channel SIP/705-00000002 joined ‘simple_bridge’ basic-bridge <12c81c89-9617-4b65-a139-2553d4d34798>
– Channel SIP/705-00000002 left ‘simple_bridge’ basic-bridge <12c81c89-9617-4b65-a139-2553d4d34798>
– Channel SIP/701-00000003 left ‘simple_bridge’ basic-bridge <12c81c89-9617-4b65-a139-2553d4d34798>
== Spawn extension (from-internal, 701, 4) exited non-zero on ‘SIP/705-00000002’
– Executing [h@from-internal:1] Macro(“SIP/705-00000002”, “hangupcall”) in new stack
– Executing [s@macro-hangupcall:1] GotoIf(“SIP/705-00000002”, “1?theend”) in new stack
– Goto (macro-hangupcall,s,3)
– Executing [s@macro-hangupcall:3] ExecIf(“SIP/705-00000002”, “0?Set(CDR(recordingfile)=)”) in new stack
– Executing [s@macro-hangupcall:4] NoOp(“SIP/705-00000002”, "SIP/701-00000003 montior file= ") in new stack
– Executing [s@macro-hangupcall:5] GotoIf(“SIP/705-00000002”, “1?skipagi”) in new stack
– Goto (macro-hangupcall,s,7)
– Executing [s@macro-hangupcall:7] Hangup(“SIP/705-00000002”, “”) in new stack
== Spawn extension (macro-hangupcall, s, 7) exited non-zero on ‘SIP/705-00000002’ in macro ‘hangupcall’
== Spawn extension (from-internal, h, 1) exited non-zero on ‘SIP/705-00000002’