Hi,
I am using Asterisk certified/16.8-cert3
and in AGI I am setting the static value and need to retrieve or get the same value
$fastagi->set_variable(“plan_id”, 123);
$plan_id = $fastagi->get_variable(‘plan_id’);
$fastagi->verbose(“MYRESULT->”.$plan_id);
Below is my full debug log line where it shows that I am getting the value “123” but not able to use that in the same AGI, just wanted to know the functionality for get_variable
[Jan 18 07:10:43] DEBUG[853153][C-00000002]: pbx_variables.c:375 ast_str_retrieve_variable: Result of ‘plan_id’ is ‘123’
Why are you using a certified version, rather than the latest, when you aren’t getting paid support from Sangoma?
Which AGI class library are you using?
You don’t appear to have enabled AGI debugging.
Hi @david551
I will upgrade to Asterisk 18.1
and currently, we are using PHP-AGI 2.2
Below is the AGI Debug enabled logs where I am getting the information that get_variable has the value “123” but unable to use that in my agi file
<PJSIP/1002202-0000000c>AGI Tx >> 200 result=1
<PJSIP/1002202-0000000c>AGI Rx << GET VARIABLE plan_id
<PJSIP/1002202-0000000c>AGI Tx >> 200 result=1 (123)
That suggests the problem lies with the library, rather than Asterisk.
declare the variable on the php enviroment
$myvar=123;
looks this method set_variable() doesnt not create the variable on php side.
Please post code snippets wrapped in preformatted text tags so the forum software does not eat important characters like ‘$’ or change quotes to funky quotes.
Your console log snippet shows you retrieved the channel variable, but not what happened when you execute ‘verbose()’. It probably looks like:
<SIP/poly-77a1-00000007>AGI Rx << VERBOSE "MYRESULT->Array" 1
example.php: MYRESULT->Array
<SIP/poly-77a1-00000007>AGI Tx >> 200 result=1
meaning ‘$plan_id’ is an array, not a scalar.
The ‘get_variable()’ method, returns an array. The array consists of 3 members: code, data, and result. You can access the members like:
$agi->verbose('code->'.$plan_id['code']);
$agi->verbose('data->'.$plan_id['data']);
$agi->verbose('result->'.$plan_id['result']);
Which will result in a console log like:
<SIP/poly-77a1-00000008>AGI Rx << VERBOSE "code->200" 1
example.php: code->200
<SIP/poly-77a1-00000008>AGI Tx >> 200 result=1
<SIP/poly-77a1-00000008>AGI Rx << VERBOSE "data->123" 1
example.php: data->123
<SIP/poly-77a1-00000008>AGI Tx >> 200 result=1
<SIP/poly-77a1-00000008>AGI Rx << VERBOSE "result->1" 1
example.php: result->1
1 Like
sedwards:
The ‘get-variable()’ method, returns an array. The array consists of 3 members: code, data, and result. You can access the members like:
If return an arrary then is just use the key and value holding the data
Hi @sedwards , Thanks but it is not working in my case as I am using fastagi on Ast 18.1.1 with PHP-AGI 2.2
$fastagi->set_variable("plan_id", "123654");
$plan_id = $fastagi->get_variable("plan_id");
$fastagi->verbose(print_r($plan_id, TRUE));
$fastagi->verbose(print_r(${plan_id}, TRUE));
$fastagi->verbose('code->'.$plan_id['code']);
$fastagi->verbose('data->'.$plan_id['data']);
$fastagi->verbose('result->'.$plan_id['result']);
================LOGS=======================
<PJSIP/1002202-00000015>AGI Tx >> 200 result=1
<PJSIP/1002202-00000015>AGI Rx << GET VARIABLE plan_id
<PJSIP/1002202-00000015>AGI Tx >> 200 result=1 (123654)
<PJSIP/1002202-00000015>AGI Rx << VERBOSE "Array" 1
agi://127.0.0.1:4761/check.php,18000000000: Array
<PJSIP/1002202-00000015>AGI Tx >> 200 result=1
<PJSIP/1002202-00000015>AGI Rx << VERBOSE "(" 1
agi://127.0.0.1:4761/check.php,18000000000: (
<PJSIP/1002202-00000015>AGI Tx >> 200 result=1
<PJSIP/1002202-00000015>AGI Rx << VERBOSE " [code] => 200" 1
agi://127.0.0.1:4761/check.php,18000000000: [code] => 200
<PJSIP/1002202-00000015>AGI Tx >> 200 result=1
<PJSIP/1002202-00000015>AGI Rx << VERBOSE " [result] => 1" 1
agi://127.0.0.1:4761/check.php,18000000000: [result] => 1
<PJSIP/1002202-00000015>AGI Tx >> 200 result=1
<PJSIP/1002202-00000015>AGI Rx << VERBOSE " [data] => " 1
agi://127.0.0.1:4761/check.php,18000000000: [data] =>
<PJSIP/1002202-00000015>AGI Tx >> 200 result=1
<PJSIP/1002202-00000015>AGI Rx << VERBOSE ")" 1
agi://127.0.0.1:4761/check.php,18000000000: )
<PJSIP/1002202-00000015>AGI Tx >> 200 result=1
<PJSIP/1002202-00000015>AGI Rx << VERBOSE "" 1
agi://127.0.0.1:4761/check.php,18000000000:
<PJSIP/1002202-00000015>AGI Tx >> 200 result=1
<PJSIP/1002202-00000015>AGI Rx << VERBOSE "Array" 1
agi://127.0.0.1:4761/check.php,18000000000: Array
<PJSIP/1002202-00000015>AGI Tx >> 200 result=1
<PJSIP/1002202-00000015>AGI Rx << VERBOSE "(" 1
agi://127.0.0.1:4761/check.php,18000000000: (
<PJSIP/1002202-00000015>AGI Tx >> 200 result=1
<PJSIP/1002202-00000015>AGI Rx << VERBOSE " [code] => 200" 1
agi://127.0.0.1:4761/check.php,18000000000: [code] => 200
<PJSIP/1002202-00000015>AGI Tx >> 200 result=1
<PJSIP/1002202-00000015>AGI Rx << VERBOSE " [result] => 1" 1
agi://127.0.0.1:4761/check.php,18000000000: [result] => 1
<PJSIP/1002202-00000015>AGI Tx >> 200 result=1
<PJSIP/1002202-00000015>AGI Rx << VERBOSE " [data] => " 1
agi://127.0.0.1:4761/check.php,18000000000: [data] =>
<PJSIP/1002202-00000015>AGI Tx >> 200 result=1
<PJSIP/1002202-00000015>AGI Rx << VERBOSE ")" 1
agi://127.0.0.1:4761/check.php,18000000000: )
<PJSIP/1002202-00000015>AGI Tx >> 200 result=1
<PJSIP/1002202-00000015>AGI Rx << VERBOSE "" 1
agi://127.0.0.1:4761/check.php,18000000000:
<PJSIP/1002202-00000015>AGI Tx >> 200 result=1
<PJSIP/1002202-00000015>AGI Rx << VERBOSE "code->200" 1
agi://127.0.0.1:4761/check.php,18000000000: code->200
<PJSIP/1002202-00000015>AGI Tx >> 200 result=1
<PJSIP/1002202-00000015>AGI Rx << VERBOSE "data->" 1
agi://127.0.0.1:4761/check.php,18000000000: data->
<PJSIP/1002202-00000015>AGI Tx >> 200 result=1
<PJSIP/1002202-00000015>AGI Rx << VERBOSE "result->1" 1
agi://127.0.0.1:4761/check.php,18000000000: result->1
<PJSIP/1002202-00000015>AGI Tx >> 200 result=1
<PJSIP/1002202-00000015>AGI Rx << SET VARIABLE plan_id "123654"
Which version of AGI you are using?
At this stage of the game, I don’t think fastagi is your issue. Try just ‘plain agi’ to confirm.
The AGI protocol is a line oriented request/response kind of animal – you issue 1 request, you read 1 response, lather, rinse, repeat.
I suspect using print_r() is your issue. This is going to output a mulit-line description of $plan_id, thus, breaking the AGI protocol. Try it without the 2 verbose(print_r()) statements.
Which version of phpagi am I using? 2.20.
system
Closed
February 20, 2021, 7:58am
10
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.