# Get variable answeredtime -- help

**URL:** <https://community.asterisk.org/t/get-variable-answeredtime-help/37173>\
**Category:** Asterisk Support\
**Created:** [October 26, 2011, 10:26pm UTC](https://community.asterisk.org/t/get-variable-answeredtime-help/37173 "2011-10-26T22:26:15Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![mikeosake](https://avatars.discourse-cdn.com/v4/letter/m/8c91f0/32.png) [@mikeosake](https://community.asterisk.org/u/mikeosake)\
**Post date:** [October 26, 2011, 10:26pm UTC](https://community.asterisk.org/t/get-variable-answeredtime-help/37173/1 "2011-10-26T22:26:15Z")

</div>

Hi,

execute\_agi(‘STREAM FILE you-entered “”’);  
execute\_agi(‘STREAM FILE goodbye “”’);  
$rc = execute\_agi("GET VARIABLE ANSWEREDTIME ");  
file\_get\_contents(“[http://localhost/mclapi/newd.php?call=".$rc[‘data’]."](http://localhost/mclapi/newd.php?call=%22.%24rc%5B'data'%5D.%22)”);  
execute\_agi(‘HANGUP’);

I am trying to pass the total answered call duration to a URL, the url is called but i cannot access the duration.  
Can someone please show me a code that gets the ANSWEREDTIME?

Thanks Alot  
Michael

---

<div class="post-metadata">

**Author:** ![SGM](https://avatars.discourse-cdn.com/v4/letter/s/ac91a4/32.png) [@SGM](https://community.asterisk.org/u/SGM)\
**Post date:** [October 27, 2011, 12:03am UTC](https://community.asterisk.org/t/get-variable-answeredtime-help/37173/2 "2011-10-27T00:03:37Z")

</div>

If you need the total call duration, after it got bridged you should use at billsec CDR entry.

---

<div class="post-metadata">

**Author:** ![mikeosake](https://avatars.discourse-cdn.com/v4/letter/m/8c91f0/32.png) [@mikeosake](https://community.asterisk.org/u/mikeosake)\
**Post date:** [October 27, 2011, 6:58am UTC](https://community.asterisk.org/t/get-variable-answeredtime-help/37173/3 "2011-10-27T06:58:51Z")

</div>

Hi,

Id the any way to get this done using phpagi?

Michael

---

<div class="post-metadata">

**Author:** ![SGM](https://avatars.discourse-cdn.com/v4/letter/s/ac91a4/32.png) [@SGM](https://community.asterisk.org/u/SGM)\
**Post date:** [October 27, 2011, 7:01am UTC](https://community.asterisk.org/t/get-variable-answeredtime-help/37173/4 "2011-10-27T07:01:48Z")

</div>

I suppose… It should be something like get\_variable(‘CDR(billsec)’).

---

<div class="post-metadata">

**Author:** ![mikeosake](https://avatars.discourse-cdn.com/v4/letter/m/8c91f0/32.png) [@mikeosake](https://community.asterisk.org/u/mikeosake)\
**Post date:** [October 27, 2011, 9:01am UTC](https://community.asterisk.org/t/get-variable-answeredtime-help/37173/5 "2011-10-27T09:01:48Z")

</div>

Hi,

Thanks for that. i get this result when i use ‘CDR(billsec)’

newz.php: Array  
newz.php: (  
newz.php: [code] =\> 200  
newz.php: [result] =\> 1  
newz.php: [data] =\> 0  
newz.php: )

When i use $totaltime=$AGI-\>get\_variable(“ANSWEREDTIME”); i get  
newz.php: Array  
newz.php: (  
newz.php: [code] =\> 200  
newz.php: [result] =\> 0  
newz.php: [data] =\>  
newz.php: )

The call record on my phone is 13secs, i want to be able to capture that.  
Is this possible?

Michael

---

<div class="post-metadata">

**Author:** ![SGM](https://avatars.discourse-cdn.com/v4/letter/s/ac91a4/32.png) [@SGM](https://community.asterisk.org/u/SGM)\
**Post date:** [October 27, 2011, 9:16am UTC](https://community.asterisk.org/t/get-variable-answeredtime-help/37173/6 "2011-10-27T09:16:15Z")

</div>

Actually you should use get\_variable(‘CDR(billsec)’, true) to get the data returned, instead of an array. As far as I remember to get the accurate billsec you should do this after the channel has been hung up.

---

<div class="post-metadata">

**Author:** ![mikeosake](https://avatars.discourse-cdn.com/v4/letter/m/8c91f0/32.png) [@mikeosake](https://community.asterisk.org/u/mikeosake)\
**Post date:** [October 27, 2011, 9:30am UTC](https://community.asterisk.org/t/get-variable-answeredtime-help/37173/7 "2011-10-27T09:30:13Z")

</div>

Hi,

Please view my code, i am still kinda new to this so maybe you can point out my mistake

CODE  
set\_time\_limit(30);  
require(‘phpagi.php’);  
error\_reporting(E\_ALL);  
$agi = new AGI();  
$agi-\>answer();

$cid = $agi-\>parse\_callerid();  
$agi-\>stream\_file(“please-enter-your-extension-then-press-pound”,"#");  
$result = $agi-\>get\_data(“beep”, 9000, 20);  
$agi-\>verbose($result);  
$keys = $result[‘result’];  
$agi-\>stream\_file(“you-entered”);  
$agi-\>say\_digits($keys);  
$agi-\>stream\_file(‘thank-you-for-calling’);  
$agi-\>stream\_file(‘goodbye’);  
$agi-\>hangup();  
$vv=$agi-\>get\_variable(‘CDR(billsec)’,true);  
$agi-\>verbose($vv);

OUTPUT  
– Attempting call on SIP/XXXXX/08098009386 for application AGI(newz.php) (Retry 1)  
== Using SIP RTP TOS bits 184  
== Using SIP RTP CoS mark 5  
== Using SIP VRTP TOS bits 136  
== Using SIP VRTP CoS mark 6  
\> Channel SIP/XXXX-0000006a was answered.  
\> Launching AGI(newz.php) on SIP/XXXX-0000006a  
– Launched AGI Script /var/lib/asterisk/agi-bin/newz.php  
– Playing ‘please-enter-your-extension-then-press-pound’ (escape\_digits=#) (sample\_offset 0)  
– \<SIP/MCL\_GW-0000006a\> Playing ‘beep.gsm’ (language ‘en’)  
newz.php: Array  
newz.php: (  
newz.php: [code] =\> 200  
newz.php: [result] =\> 5555  
newz.php: [data] =\>  
newz.php: )  
newz.php:  
– Playing ‘you-entered’ (escape\_digits=) (sample\_offset 0)  
– \<SIP/MCL\_GW-0000006a\> Playing ‘digits/5.gsm’ (language ‘en’)  
– \<SIP/MCL\_GW-0000006a\> Playing ‘digits/5.gsm’ (language ‘en’)  
– \<SIP/MCL\_GW-0000006a\> Playing ‘digits/5.gsm’ (language ‘en’)  
– \<SIP/MCL\_GW-0000006a\> Playing ‘digits/5.gsm’ (language ‘en’)  
– Playing ‘thank-you-for-calling’ (escape\_digits=) (sample\_offset 0)  
– Playing ‘goodbye’ (escape\_digits=) (sample\_offset 0)  
trixbox1\*CLI\>

I dont get see the value of (‘CDR(billsec)’,true) in the debug information.  
What am i doing wrong?

Michael

---

<div class="post-metadata">

**Author:** ![SGM](https://avatars.discourse-cdn.com/v4/letter/s/ac91a4/32.png) [@SGM](https://community.asterisk.org/u/SGM)\
**Post date:** [October 27, 2011, 9:37am UTC](https://community.asterisk.org/t/get-variable-answeredtime-help/37173/8 "2011-10-27T09:37:44Z")

</div>

I meant calling the AGI script from the dialplan after the hangup (h extension). Haven’t done this in quite a while. I’m gonna have to check my implementations to give you a better example.

---

<div class="post-metadata">

**Author:** ![mikeosake](https://avatars.discourse-cdn.com/v4/letter/m/8c91f0/32.png) [@mikeosake](https://community.asterisk.org/u/mikeosake)\
**Post date:** [October 27, 2011, 9:51am UTC](https://community.asterisk.org/t/get-variable-answeredtime-help/37173/9 "2011-10-27T09:51:58Z")

</div>

Hi,

This is what i want to do:

1. Trigger a Call using a call file
2. Take a 4 digit PIN
3. Say good by
4. Send PIN/Call Duration/Call Status to a URL.
5. END

Just so you have a clear picture of what i am trying to achieve.

Michael
