-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathSystemHelper.php
40 lines (36 loc) · 986 Bytes
/
SystemHelper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
namespace mgcode\helpers;
class SystemHelper
{
const OS_WINDOWS = 'windows';
const OS_LINUX = 'linux';
/**
* Runs cli command in background
* @param $command
*/
public static function runBackgroundCommand($command)
{
$os = static::getOperatingSystem();
if ($os == static::OS_WINDOWS) {
$execCommand = $command.' > NUL';
$WshShell = new \COM('WScript.Shell');
$WshShell->Run($execCommand, 0, false);
} else if ($os == static::OS_LINUX) {
$execCommand = 'bash -c "exec nohup setsid '.$command.' > /dev/null 2>&1 &"';
exec($execCommand);
}
}
/**
* Returns current OS type
* @static
* @return string
*/
public static function getOperatingSystem()
{
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
return static::OS_WINDOWS;
} else {
return static::OS_LINUX;
}
}
}