Using the new Concurrency Facade with Laravel Herd

September 15, 2024 (2mo ago)

Taylor Otwell recently added a cool new Concurrency facade which he announced and showed off at Laracon 2024. This is such a great new feature as it allows for multiple concurrent tasks at the same time. If you're like me, this is a game-changer when you are running multiple analytical queries, as the time each one takes adds up fast.

However at the time of writing, the Concurrency facade doesn't yet work with Laravel Herd. There is an open pull request within Symfony that fixes this.

But if you're like me and feeling impatient, you can add the following 'hacky' code to your AppServiceProvider to get this working:

app/Providers/AppServiceProvider.php
public function boot()
{
    if(app()->environment('local')) {
        // set the PHP_BINARY env
        $path = getenv('HERD_HOME') . \DIRECTORY_SEPARATOR . 'bin';
        $phpBinary = (new ExecutableFinder)->find('php', false, [$path]);
 
        putenv('PHP_BINARY=' . $phpBinary);
    }
}

Thanks to Marcel Pociot's PR as I didn't know about the HERD_HOME env variable.

If you're interested in the full pull request, you can find it here. Once this is merged, you can remove the hacky code from your AppServiceProvider.