[asterisk-users] Forking AGI or GoSub

Dovid Bender dovid at telecurve.com
Mon Apr 22 12:26:59 CDT 2019


Eric,

As I mentioned before that does not seem to work with PHP

  == Using SIP RTP CoS mark 5
    -- Executing [my_test_test at from-external:1]
NoOp("SIP/fpp-55559999-000009ca", "") in new stack
    -- Executing [my_test_test at from-external:2]
AGI("SIP/fpp-55559999-000009ca",
"fast_agi_wrapper,my_test,cnum=10000009&cname=Dovid Bender") in new stack
    -- Launched AGI Script /opt/dovid/fastagi/fast_agi_wrapper
 fast_agi_wrapper,my_test,cnum=10000009&cname=Dovid Bender: We are the
parent. Let's die!
 fast_agi_wrapper,my_test,cnum=10000009&cname=Dovid Bender: We are child
here. Taking a nap !
 fast_agi_wrapper,my_test,cnum=10000009&cname=Dovid Bender: That nap was
goooood!
    -- <SIP/fpp-55559999-000009ca>AGI Script
/opt/dovid/fastagi/fast_agi_wrapper completed, returning 0
    -- Executing [my_test_test at from-external:3]
Playback("SIP/fpp-55559999-000009ca", "tt-monkeys") in new stack
    -- <SIP/fpp-55559999-000009ca> Playing 'tt-monkeys.slin' (language 'en')
    -- Remote UNIX connection
    -- Remote UNIX connection disconnected


My code:
<?PHP


$pid = pcntl_fork();
if ($pid != 0) {
     // we are the parent
     // do parent stuff
        $fastagi->verbose("We are the parent. Let's die!");
     exit;
}

// we are the child, detatch from terminal
$sid = posix_setsid();
if ($sid < 0) {
     die;
}
// do child stuff

        $fastagi->verbose("We are child here. Taking a nap !");
        sleep(5);
        $fastagi->verbose("That nap was goooood!");

?>




On Fri, Apr 19, 2019 at 2:16 PM Eric Wieling <ewieling at nyigc.com> wrote:

> 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/
>
> --
> _____________________________________________________________________
> -- 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/20190422/c2ff4fa7/attachment.html>


More information about the asterisk-users mailing list