warn('Killing any existing schedule:work monitor processes using pkill...'); exec('pkill -f "schedule:work"'); } $this->info('Starting schedule:work monitor...'); while (true) { $this->warn('Killing any remaining schedule:work processes...'); if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { exec('taskkill /IM php.exe /F /FI "WINDOWTITLE eq schedule:work"'); } else { exec('pkill -f "artisan schedule:work"'); } $this->info('Starting: php artisan schedule:work'); $process = proc_open( 'php artisan schedule:work', [ 1 => ['pipe', 'w'], 2 => ['pipe', 'w'], ], $pipes ); if (is_resource($process)) { // Read output and error while ($line = fgets($pipes[1])) { $this->line(trim($line)); } while ($err = fgets($pipes[2])) { $this->error(trim($err)); } fclose($pipes[1]); fclose($pipes[2]); $status = proc_get_status($process); $pid = $status['pid'] ?? null; proc_terminate($process); return $pid; } else { $this->error('Failed to start schedule:work process. Retrying in 5 seconds...'); sleep(5); } } } }