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

Liviu Chircu liviu at opensips.org
Wed Jun 17 09:36:04 CEST 2015


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
> http://lists.opensips.org/cgi-bin/mailman/listinfo/users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opensips.org/pipermail/users/attachments/20150617/7e58d4b8/attachment.htm>


More information about the Users mailing list