0

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!

LuiKang
  • 83
  • 1
  • 7
  • I think it's not the code problem, but it's because your hosting disables your cronjob. Usually, shared hosting will block cronjob that runs every minute. – Muhammad Dyas Yaskur May 21 '20 at 22:13
  • did you try to call `shell_exec`? – A. El-zahaby May 21 '20 at 22:15
  • artisan is a php script. Why do you want to create another one? So your problem is, that you cannot run any crons any want to run it when visiting a certain route. Did I get that correct? – codedge May 21 '20 at 22:42
  • Your question is very unclear. If you want to run jobs on a schedule, [set up the scheduler](https://laravel.com/docs/7.x/scheduling). – Don't Panic May 22 '20 at 03:44
  • I can make a cron to run a script as an URL. How can I pass the 'schedule:run >> /dev/null 2>&1' parameter with URL? – LuiKang May 22 '20 at 07:21
  • Did you look at the docs I linked to? 1) [Set up the scheduler, add the cron job to run it](https://laravel.com/docs/7.x/scheduling#introduction). 2) [Write a console script to do whatever you want](https://laravel.com/docs/7.x/artisan). 3) [Schedule that script to run](https://laravel.com/docs/7.x/scheduling#scheduling-artisan-commands). It is all in the docs I linked to. If that is not what you are asking, please edit your question and try to clarify. – Don't Panic May 22 '20 at 09:08
  • @Don'tPanic I looked at all the docs, and I read that I need to run console commands. The problem is that as I pointed out in the question: I can't run any console command, just only PHP scripts. If I misunderstood anything, please help me to make a PHP script that runs the previously Laravel-scheduled tasks (those already done). – LuiKang May 22 '20 at 10:30
  • @A.El-zahaby I tried, it doesn't work unfortunately. – LuiKang May 22 '20 at 10:31

1 Answers1

0

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.

LuiKang
  • 83
  • 1
  • 7