Skip to content

Commit aa4b584

Browse files
committed
Detach the runner from the parent
1 parent 7a06f38 commit aa4b584

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/AsyncTask.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Illuminate\Process\InvokedProcess;
77
use Illuminate\Support\Facades\Process;
88
use Laravel\SerializableClosure\SerializableClosure;
9+
use loophp\phposinfo\OsInfo;
910

1011
/**
1112
* The common handler of an AsyncTask; this can be a closure (will be wrapped inside AsyncTask) or an interface instance.
@@ -68,9 +69,20 @@ public function run(): void
6869
*/
6970
public function start(): void
7071
{
71-
// assume unix for now
72+
// prepare the runner command
7273
$serializedTask = $this->toBase64Serial();
73-
$this->runnerProcess = Process::quietly()->start("php artisan async:run $serializedTask");
74+
$baseCommand = "php artisan async:run $serializedTask";
75+
76+
// then, specific actions depending on the runtime OS
77+
if (OsInfo::isWindows()) {
78+
// basically, in windows, it is too tedioous to check whether we are in cmd or ps,
79+
// but we require cmd (ps won't work here), so might as well force cmd like this
80+
$this->runnerProcess = Process::quietly()->start("cmd /c start /b $baseCommand");
81+
return;
82+
}
83+
// assume anything not windows to be unix
84+
// unix use nohup
85+
$this->runnerProcess = Process::quietly()->start("nohup $baseCommand");
7486
}
7587

7688
/**

0 commit comments

Comments
 (0)