[OpenSIPS-Users] Using $var() over $json() when casting restclient response
Tito Cumpen
tito at xsvoce.com
Wed Jun 17 23:47:01 CEST 2015
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> 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 Developerhttp://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",
> "$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 listUsers at lists.opensips.orghttp://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/20150617/7372c1ec/attachment.htm>
More information about the Users
mailing list