PHP execute command as subcommand

Posted by Thomaschaaf on Stack Overflow See other posts from Stack Overflow or by Thomaschaaf
Published on 2011-01-13T15:42:26Z Indexed on 2011/01/13 15:53 UTC
Read the original article Hit count: 295

Filed under:
|
|
|

I have the following 2 files and am executing them on linux (debian).

File1.php

<?php
exec("php -f file2.php > /dev/null 2>&1 &");
sleep(100);

File2.php

<?php
exec("sleep 30 > /dev/null 2>&1 &");
exec("sleep 30 > /dev/null 2>&1 &");
sleep(100);

The way it currently is it first starts file1.php and fires up file2.php and immediatly begins the sleep commands. It does not wait for the first sleep to finish to continue.

The problem is that the file2.php and sleep commands are not subcommands of file1.php and I can't simply kill it to kill all subcommands. My htop looks like this: http://dl.getdropbox.com/u/5910/Jing/2011-01-13_1611.png

I am searching for a way to have the commands be subcommands of file1.php so that I can easily kill them all :)

what I have:

'- php -f file2.php
'-sleep 30
'-sleep 30
'- php -f file1.php

basically I want this:

'- php -f file1.php
  '- php -f file2.php
    '-sleep 30
    '-sleep 30

© Stack Overflow or respective owner

Related posts about php

Related posts about execute