Re: Asynchronous PHP Execution
| From: | Waynn Lue | Date: | Sun, 06 Jul 2008 09:09:23 +0000 |
| Subject: | Re: Asynchronous PHP Execution | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-276327@lists.php.net to get a copy of this message | ||
>
> > and exec/shell (but that
>
>> doesn't seem to be asynchronous), but neither seems optimal.
>>
>
> It can be if you redirect the output streams and put an ampersand after it:
>
> <?php
> exec('sleep 5 > /dev/null 2>/dev/null &');
> echo 'Script ended';
> ?>
>
> This tiny sample should end immediately, and the sleep command should run
> on regardless.
>
> Thanks so much for the suggestion, that's what I ended up doing and it
worked, after some fiddling. Just as a side note, does it execute from the
current directory of the file? Previously, I tried calling exec('php
scripts/foo.php'), but it seemed like there was some weird interaction
between different required files. E.g., this was the layout:
orig.php
scripts/foo.php
incl.php
orig.php had the exec line, and foo.php had require_once(../incl.php). But
it seemed like the exec call caused foo.php to execute from the scripts
directory while the require_once caused incl.php to also execute from the
scripts directory.
How does php determine what the working directory is?