Run Window Process with PHP

1

I'm using Ubuntu Linux and running my website on an Apache server. Through PHP I'm trying to run an executable that is in a specific directory, but I want this process to run in the background and in some window for it to be maintained.

I've tried several command exec system and shell_exec and at the moment it's like this, what am I doing wrong?

$startOT = "";
if ( isset($_GET['Server']) ) {
    $startOT = trim($_GET['Server']);
}

if ($startOT == "Start") { 
    if (substr_count(shell_exec('sudo pstree'),'tfs') >= 1) { 
        echo 'Server is executing';
    }
    else {
        $startCommand = 'cd /var/www/html/datapacks/baiak860/ && sudo screen && sudo ./tfs';
        $out = shell_exec($startCommand);
        echo $out;
        echo "Server has been started!";
    }
}
    
asked by anonymous 09.05.2016 / 06:44

1 answer

0

I do not know what you want to run, but I'll give you some suggestions, at the gnu / linux terminals you can use > /dev/null & (or > /dev/null 2>&1 & ) to run a command in background , this does PHP not wait for the command:

exec($startedCommand . ' > /dev/null &');

or

exec($startedCommand . ' > /dev/null 2>&1 &');

If you want to open a new terminal screen you can try this:

exec('xterm -e "' . $startedCommand . '"');

If this holds the php process try combined with the previous commands:

exec('xterm -e "' . $startedCommand . '" > /dev/null &');

If you support the Gnome tools (Unity and xfce I believe they have) you can try this:

exec('gnome-terminal -e "' . $startedCommand . '"');

If this holds the php process try combined with the previous commands:

exec('gnome-terminal -e "' . $startedCommand . '" > /dev/null &');

There may be a problem when passing the parameter -e , so you can try to use escapeshellarg , like this:

$startedCommand = escapeshellarg($startedCommand);
exec('xterm -e "' . $startedCommand . '" > /dev/null &');

Or

$startedCommand = escapeshellarg($startedCommand);
exec('gnome-terminal -e "' . $startedCommand . '" > /dev/null &');
    
09.05.2016 / 07:11