Glancing at the code, Asterisk appears to wait for the pipe between
Asterisk and the AGI to be closed before it considers it completed. So, the
problem is this pipe is duplicated into the child.
Try adding this after setsid:
fclose(STDIN);
fclose(STDOUT);
fclose(STDERR);
fopen('/dev/null', 'r'); // set fd/0
fopen('/dev/null', 'w'); // set fd/1
fopen('php://stdout', 'w'); // a hack to duplicate fd/1 to 2
(from
https://andytson.com/blog/2010/05/daemonising-a-php-cli-script-on-a-posix-system/
)
On Mon, 22 Apr 2019 at 12:28, Dovid Bender <dovid at telecurve.com> wrote:
> 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
>
> --
> _____________________________________________________________________
> -- 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
--
Regards,
John Runyon
Simply NUC
512-766-0401 x1110
495 Round Rock West Dr, Round Rock, TX 78681
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.digium.com/pipermail/asterisk-users/attachments/20190423/05fdfc03/attachment.html>