[OpenSIPS-Users] Using $var() over $json() when casting restclient response

Liviu Chircu liviu at opensips.org
Thu Jun 18 14:21:26 CEST 2015


Hi Tito,

Make sure to read all "rest_client" module parameters. In your case, the 
async() timeout would be accomplished with the "curl_timeout" parameter [1]
If that were to happen, "rest_get()" would return a negative value, and 
you could catch it just like in the examples. [2]

[1]: 
http://www.opensips.org/html/docs/modules/2.2.x/rest_client.html#id249608
[2]: 
http://www.opensips.org/html/docs/modules/2.2.x/rest_client.html#id293823

Best regards,

Liviu Chircu
OpenSIPS Developer
http://www.opensips-solutions.com

On 18.06.2015 00:47, Tito Cumpen wrote:
> Liviu,
>
>
> Thanks for your reply. To preface my forthcoming I'd like to state at 
> the current moment the reply to this query is pretty quick. If the 
> request was to take X amount time the script would continue even 
> though a condition is based on it advancing? The reason I ask is 
> because I notice the async method was added with the intention of 
> pausing the script until the reply is received. What is the timeout 
> that would make opensips continue on with the script?
>
>
> Thanks,
> Tito
>
> On Wed, Jun 17, 2015 at 3:36 AM, Liviu Chircu <liviu at opensips.org 
> <mailto:liviu at opensips.org>> wrote:
>
>     Hi Tito,
>
>     A very interesting question. After a bit of research, I can tell
>     you that $json and $var will behave quite similarly in terms of
>     performance when using the simple "=" (assign) operator. A
>     difference between them worth pointing out is that $var uses
>     only-pkg memory, while $json uses both pkg and system memory
>     (since it is based on the "json-c" library) - so the more $json's
>     you fill up, the more "opensipsctl fifo get_statistics pkmem:"
>     will be incorrect.
>
>     If you really want to optimize something about that _specific_ code:
>
>     $json(authbody) :=$json(authresponse);
>     if ($json(authbody/message/AcceptCall) == "false") {
>         ...
>     }
>
>     Best regards,
>
>     Liviu Chircu
>     OpenSIPS Developer
>     http://www.opensips-solutions.com
>
>     On 17.06.2015 02:18, Tito Cumpen wrote:
>>     Group,
>>
>>
>>     Is there a downside to casting responses from a rest response
>>     into a json object rather than a generic $var? Here is my
>>     function it works but I want to be aware if this will cost a
>>     considerable amount of resources.
>>
>>                           if
>>     (!rest_get("http://myauthurl.com/authme/$fU/$rU
>>     <http://myauthurl.com/authme/$fU/$rU>", "$json(authresponse)",
>>     "$var(ct)", "$var(rcode)")) {
>>
>>
>>             xlog("Error code $var(rcode) in HTTP GET!\n");
>>
>>     xlog("on account of admittance error we are sending the call to
>>     the AS server for processing");
>>
>>             route(4);
>>
>>     }
>>
>>
>>                     xlog("got this body response from authority on
>>     invite $json(authresponse) with response code $var(rcode)");
>>
>>             xlog("response now casting to json  $json(authresponse) ");
>>
>>             $json(authbody) :="{}";
>>
>>
>>             $json(authbody) :=$json(authresponse);
>>
>>             xlog(" accessing the message $json(authbody/message)");
>>
>>
>>             $json(accept) :=$json(authbody/message);
>>
>>             xlog(" casted message $json(accept)");
>>
>>             if($json(accept/AcceptCall) == "false"){
>>
>>             xlog("response equal false");
>>
>>                             route(3);
>>
>>
>>
>>             }else{
>>
>>
>>
>>     Notice how the response is casted from $json(authresponse) to
>>      $json(authbody)  after it is initialized. I came to realize that
>>     I had to initialize a variable because I couldn't access keys in
>>     $json(authresponse).
>>
>>
>>
>>     Thanks,
>>
>>     Tito
>>
>>
>>
>>     _______________________________________________
>>     Users mailing list
>>     Users at lists.opensips.org  <mailto:Users at lists.opensips.org>
>>     http://lists.opensips.org/cgi-bin/mailman/listinfo/users
>
>
>     _______________________________________________
>     Users mailing list
>     Users at lists.opensips.org <mailto:Users at lists.opensips.org>
>     http://lists.opensips.org/cgi-bin/mailman/listinfo/users
>
>
>
>
> _______________________________________________
> Users mailing list
> Users at lists.opensips.org
> http://lists.opensips.org/cgi-bin/mailman/listinfo/users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opensips.org/pipermail/users/attachments/20150618/9030b6a0/attachment.htm>


More information about the Users mailing list