Re: Asynchronous PHP Execution

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Waynn Lue wrote:
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?

I think so.

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?


I believe it's the directory of the original script. So if you had:

require_once('scripts/foo.php');

...in orig.php, that would be correct.

--
Richard Heyes

Employ me:
http://www.phpguru.org/cv

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux