Running a Script in the Background?

Discussion in 'PHP' started by tdd1984, Jun 6, 2008.

  1. #1
    I was just curious how can I run a script in the background I'd imainge I use the Shell_exec() function through PHP then find the PID and kill it when I need to?

    The reason I ask for is because the script could run for several days, but at the same time I will monitor its status through my administration section, but at the same time I want to be able to log out of my admin and come back the next day to check its status...

    How could I do this?

    I would need to kill it sooner or later...
     
    tdd1984, Jun 6, 2008 IP
  2. Lordo

    Lordo Well-Known Member

    Messages:
    2,082
    Likes Received:
    58
    Best Answers:
    0
    Trophy Points:
    190
    #2
    shell_exec will do that since it can be used to run any system command. Run it using shell_exec (and add & to it to run in the background) then when you need to kill it, run any command like "ps ax | grep 'the file_name'", process the output to get the process ID and then kill it using shell_exec too.
     
    Lordo, Jun 6, 2008 IP
  3. tdd1984

    tdd1984 Well-Known Member

    Messages:
    2,357
    Likes Received:
    42
    Best Answers:
    0
    Trophy Points:
    150
    #3

    You don't know where I can get a tutorial on how to do this do you?
     
    tdd1984, Jun 6, 2008 IP
  4. Lordo

    Lordo Well-Known Member

    Messages:
    2,082
    Likes Received:
    58
    Best Answers:
    0
    Trophy Points:
    190
    #4
    Hmmm no but you can look for them one by one.

    1. Run unix command in background
    2. Run a unix command from php

    You will find it easy.
     
    Lordo, Jun 7, 2008 IP