exec background process

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Matt

    #1

    exec background process

    I want have PHP call another process (another PHP script at the moment
    but it may end up being a binary) in the background and not wait for
    process to complete, but rather instantly jump the the next line of
    code.

    I've tried things like:

    exec("./script.php &"); // script.php has executable permissions set
    exec("at -f ./script.php now"); // and #!/usr/bin/php at the top of
    the code

    Neither seem to work. They both execute script.php, but both hang
    around until script.php has completed.

    Any ideas?
  • Jon Kraft

    #2
    Re: exec background process

    Matt <google@mralsto n.com> wrote:
    [color=blue]
    > I want have PHP call another process (another PHP script at the moment
    > but it may end up being a binary) in the background and not wait for
    > process to complete, but rather instantly jump the the next line of
    > code.
    >
    > I've tried things like:
    >
    > exec("./script.php &"); // script.php has executable permissions set
    > exec("at -f ./script.php now"); // and #!/usr/bin/php at the top of
    > the code
    >
    > Neither seem to work. They both execute script.php, but both hang
    > around until script.php has completed.[/color]

    Hi Matt,

    You could use proc_open for this:

    proc_close(proc _open ("./script.php &", array(), $foo));

    The empty array for the output specs prevents opening any pipes to the new
    process, so proc_open doesn't wait for the execution of script.php to
    finish - the last parameter is just there because it has to be.
    proc_close() closes the process immediately, so your PHP script doesn't
    stop.

    HTH;
    JOn

    Comment

    Working...