Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

rodrigopedra
Copy link
Contributor

Working on an artisan command that starts some concurrent processes and monitors them, I wanted to output the full command line of those processes for monitoring.

For example:

$pool = Process::pool(function (Pool $pool) {
    // commands
})->start();

while ($pool->running()->isNotEmpty()) {
    $this->table(
        ['#', 'command'],
        $pool->running()->map(function (InvokedProcess $process) {
            $commandLine = (fn () => $this->process->getCommandLine())
                ->bindTo($process, $process);

            return [$process->id(), $commandLine()];
        })->all(),
    );

    Sleep::for(1)->second();
}

$pool->wait();

This would output a table with the current commands being run for each elapsed second.

As I couldn't retrieve the command line, I needed to use the Closure bind hack to access the InvokedProcess' protected $process property and grab the command line.

This PR

  • Adds the command() method both to InvokedProcess and FakeInvokedProcess to retrieve a pooled process' command line.

If this PR is accepted, I will send a PR to the master branch to add this method to the Illuminate\Contracts\Process\InvokedProcess interface.

@rodrigopedra
Copy link
Contributor Author

Failing test is unrelated to the changes in this PR:

There was 1 failure:

1) Illuminate\Tests\Support\SleepTest::testItSleepsForSecondsWithMilliseconds
Failed asserting that 1.6 matches expected 1.5.

D:\a\framework\framework\tests\Support\SleepTest.php:63

@taylorotwell taylorotwell merged commit 2733fc7 into laravel:12.x Sep 3, 2025
45 of 65 checks passed
@rodrigopedra rodrigopedra deleted the feature-process branch September 3, 2025 16:53
@AhmedAlaa4611
Copy link
Contributor

Since it's been accepted, just reminding you of your note about sending a follow-up PR to the master branch to add the method to the Illuminate\Contracts\Process\InvokedProcess.

@rodrigopedra
Copy link
Contributor Author

@AhmedAlaa4611 I am waiting for the changes on the 12.x branch to be merged on the master branch first.

@rodrigopedra
Copy link
Contributor Author

@AhmedAlaa4611 sent PR #56978. Thanks! =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants