I have an AGI that can sometimes take time complete. I don't want the dialplan to be held up by the agi. Is there any way to call it and have Asterisk continue with the dialplan? -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.digium.com/pipermail/asterisk-users/attachments/20190410/4c704231/attachment.html>
On 4/10/2019 3:54 PM, Dovid Bender wrote:> I have an AGI that can sometimes take time complete. I don't want the dialplan to be held up by the agi. Is there any way to call it and have Asterisk continue with the dialplan? >Is there a reason you can't fork in the AGI and just return to the dialplan in the parent? -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.digium.com/pipermail/asterisk-users/attachments/20190410/582202bd/attachment.html>
On Wed, 10 Apr 2019, Dovid Bender wrote:> I have an AGI that can sometimes take time complete. I don't want the > dialplan to be held up by the agi. Is there any way to call it and have > Asterisk continue with the dialplan?On Wed, 10 Apr 2019, Dovid Bender wrote:> I have an AGI that can sometimes take time complete. I don't want the > dialplan to be held up by the agi. Is there any way to call it and have > Asterisk continue with the dialplan?I had a situation that required this functionality -- processing a credit card could take a second or two and we didn't want 'dead air' for our user experience. I created a pthread to play 'Please hold on while we process your card and get ready for a good time...' while the main program continued with the card authorization. Most of the time the auth completed before the audio finished so it appeared to be instantaneous to the caller. The only caveat is to not interact (stdin/stdout) with Asterisk until 'stream file' in the thread completed. -- Thanks in advance, ------------------------------------------------------------------------- Steve Edwards sedwards at sedwards.com Voice: +1-760-468-3867 PST https://www.linkedin.com/in/steve-edwards-4244281
Steve, In my case this is for emergency services. The AGI calls a web URL with the callers information. The call passes through Asterisk and we don't want to delay the call at all if the API takes 1-2 extra seconds. On Wed, Apr 10, 2019 at 10:01 PM Steve Edwards <asterisk.org at sedwards.com> wrote:> On Wed, 10 Apr 2019, Dovid Bender wrote: > > > I have an AGI that can sometimes take time complete. I don't want the > > dialplan to be held up by the agi. Is there any way to call it and have > > Asterisk continue with the dialplan? > > On Wed, 10 Apr 2019, Dovid Bender wrote: > > > I have an AGI that can sometimes take time complete. I don't want the > > dialplan to be held up by the agi. Is there any way to call it and have > > Asterisk continue with the dialplan? > > I had a situation that required this functionality -- processing a credit > card could take a second or two and we didn't want 'dead air' for our user > experience. > > I created a pthread to play 'Please hold on while we process your card and > get ready for a good time...' while the main program continued with the > card authorization. > > Most of the time the auth completed before the audio finished so it > appeared to be instantaneous to the caller. > > The only caveat is to not interact (stdin/stdout) with Asterisk until > 'stream file' in the thread completed. > > -- > Thanks in advance, > ------------------------------------------------------------------------- > Steve Edwards sedwards at sedwards.com Voice: +1-760-468-3867 PST > https://www.linkedin.com/in/steve-edwards-4244281 > > -- > _____________________________________________________________________ > -- Bandwidth and Colocation Provided by http://www.api-digital.com -- > > Check out the new Asterisk community forum at: > https://community.asterisk.org/ > > New to Asterisk? Start here: > https://wiki.asterisk.org/wiki/display/AST/Getting+Started > > asterisk-users mailing list > To UNSUBSCRIBE or update options visit: > http://lists.digium.com/mailman/listinfo/asterisk-users-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.digium.com/pipermail/asterisk-users/attachments/20190419/de27ba1f/attachment.html>
Mark, I am using PHP agi and when forking the call does not continue util the forked process is done. Am I doing it wrong? On Wed, Apr 10, 2019 at 4:27 PM Mark Wiater <mark.wiater at greybeam.com> wrote:> On 4/10/2019 3:54 PM, Dovid Bender wrote: > > I have an AGI that can sometimes take time complete. I don't want the > dialplan to be held up by the agi. Is there any way to call it and have > Asterisk continue with the dialplan? > > > Is there a reason you can't fork in the AGI and just return to the > dialplan in the parent? > -- > _____________________________________________________________________ > -- Bandwidth and Colocation Provided by http://www.api-digital.com -- > > Check out the new Asterisk community forum at: > https://community.asterisk.org/ > > New to Asterisk? Start here: > https://wiki.asterisk.org/wiki/display/AST/Getting+Started > > asterisk-users mailing list > To UNSUBSCRIBE or update options visit: > http://lists.digium.com/mailman/listinfo/asterisk-users-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.digium.com/pipermail/asterisk-users/attachments/20190419/853c0109/attachment.html>
On 4/19/2019 1:49 PM, Dovid Bender wrote:> Mark, > > I am using PHP agi and when forking the call does not continue util > the forked process is done. Am I doing it wrong? > > > On Wed, Apr 10, 2019 at 4:27 PM Mark Wiater <mark.wiater at greybeam.com > <mailto:mark.wiater at greybeam.com>> wrote: > > On 4/10/2019 3:54 PM, Dovid Bender wrote: >> I have an AGI that can sometimes take time complete. I don't want >> the dialplan to be held up by the agi. Is there any way to call >> it and have Asterisk continue with the dialplan? >> > > Is there a reason you can't fork in the AGI and just return to the > dialplan in the parent? >Dovid, I'm not much of a PHP person, but in perl, i check the process id that's returned from fork() and exit if it's 1 (parent) and keep processing if it's the child (greater than 1). I think php uses pcntl_fork(). Is that how you're doing it? -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.digium.com/pipermail/asterisk-users/attachments/20190419/40e4ea7e/attachment.html>
I am very much a PHP person. PHP doesn't really have an elegant way to handle forking / threading, which can make it non-trivial to implement and can be unreliable if the implementation is not exact. PHP must also be compiled to be thread safe in order to do this properly. Granted, the last time I looked into this with PHP was under PHP 5.6, and tests at that time did not yield the results we wanted. We ultimately moved to Python when we needed multi-threading, which is extremely elegant and reliable for this application. [cid:image001.png at 01D4F6B9.8C1499D0] Michael J. Munger, dCAP, MCPS, MCNPS, MBSS Microsoft Certified Professional Microsoft Certified Small Business Specialist Digium Certified Asterisk Professional High Powered Help, Inc. p: 678-905-8569 w: hph.io<https://hph.io> e: mj at hph.io<mailto:mj at hph.io> From: asterisk-users <asterisk-users-bounces at lists.digium.com> On Behalf Of Mark Wiater Sent: Friday, April 19, 2019 2:00 PM To: asterisk-users at lists.digium.com Subject: Re: [asterisk-users] Forking AGI or GoSub On 4/19/2019 1:49 PM, Dovid Bender wrote: Mark, I am using PHP agi and when forking the call does not continue util the forked process is done. Am I doing it wrong? On Wed, Apr 10, 2019 at 4:27 PM Mark Wiater <mark.wiater at greybeam.com<mailto:mark.wiater at greybeam.com>> wrote: On 4/10/2019 3:54 PM, Dovid Bender wrote: I have an AGI that can sometimes take time complete. I don't want the dialplan to be held up by the agi. Is there any way to call it and have Asterisk continue with the dialplan? Is there a reason you can't fork in the AGI and just return to the dialplan in the parent? Dovid, I'm not much of a PHP person, but in perl, i check the process id that's returned from fork() and exit if it's 1 (parent) and keep processing if it's the child (greater than 1). I think php uses pcntl_fork(). Is that how you're doing it? -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.digium.com/pipermail/asterisk-users/attachments/20190419/2da95224/attachment.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: image001.png Type: image/png Size: 738 bytes Desc: image001.png URL: <http://lists.digium.com/pipermail/asterisk-users/attachments/20190419/2da95224/attachment.png>
In PHP something like: $pid = pcntl_fork(); if ($pid != 0) { // we are the parent // do parent stuff exit; } // we are the child, detatch from terminal $sid = posix_setsid(); if ($sid < 0) { die; } // do child stuff On 04/19/2019 02:00 PM, Mark Wiater wrote:> On 4/19/2019 1:49 PM, Dovid Bender wrote: >> Mark, >> >> I am using PHP agi and when forking the call does not continue util >> the forked process is done. Am I doing it wrong? >> >> >> On Wed, Apr 10, 2019 at 4:27 PM Mark Wiater <mark.wiater at greybeam.com >> <mailto:mark.wiater at greybeam.com>> wrote: >> >> On 4/10/2019 3:54 PM, Dovid Bender wrote: >>> I have an AGI that can sometimes take time complete. I don't want >>> the dialplan to be held up by the agi. Is there any way to call >>> it and have Asterisk continue with the dialplan? >>> >> >> Is there a reason you can't fork in the AGI and just return to the >> dialplan in the parent? >> > Dovid, > > I'm not much of a PHP person, but in perl, i check the process id that's > returned from fork() and exit if it's 1 (parent) and keep processing if > it's the child (greater than 1). > > I think php uses pcntl_fork(). > > Is that how you're doing it? > > >-- http://help.nyigc.net/