Search code examples
phplaravellaravel-artisan

Laravel Artisan call from PHP without CLI terminal


I would like to use a program (Freescout) as a Laravel program. It works fine, except I have to make a cron job: * * * * * php /var/userdata/web/.../website/helpdesk/artisan schedule:run >> /dev/null 2>&1

, but I can't run it in terminal, can't use any CLI, just set up a Cron to run PHP script. (shared hosting server).

So I've created a file called artisan_schedule_runner.php It would simple do:

Route::get('/foo', function () {
    Artisan::call('schedule:run >> /dev/null 2>&1');
    //
});

How should I extend my code to get it work?

Thank you in advance!


Solution

  • It seems I found the solution, and made my question solved: Artisan::call() outside the Laravel framework

    $kernel = $app->make(Illuminate\Contracts\Console\Kernel::class); 
    $input = new Symfony\Component\Console\Input\ArrayInput(['command' => 'schedule:run']);
    $output = new Symfony\Component\Console\Output\StreamOutput(fopen('output.log', 'a', false)); 
    $status = $kernel->handle( $input, $output );
    

    That runs the prevously defined schedules.