Add Grav scheduler as a php script

Hello everyone.

I have a grav production site on a shared hosting (OVH) that allows limited ssh and cron jobs.
I’d like to enable the grav scheduler for automatic backup (and other tasks).

If I try the command line in ssh, I am not able to launch cron:

(crontab -l; echo "* * * * * cd /home/XXXXXX/www;/usr/local/php8.1/bin/php bin/grav scheduler 1>> /dev/null 2>&1") | crontab -
-ovh_ssh: crontab : commande introuvable

This shared hosting allows to add php script, and only php scripts, to crontab : see here in French.

Is it possible to execute the scheduler inside a php script?

well, shared hosting is always limited in several ways, I also use it for my grav website, with similar restrictions than yours.
especially, there is no crontab available, so no wonder the given example does not work.
but, as the grav scheduler is in fact run as a command line argument to the php script ‘grav’ , you should be able to run it hourly or what else your hosting allows, provided your hosting allows command line arguments to the scheduled script.
just provide the correct path (from inside the hosting !) for the ‘grav’ script in the form, together with ‘scheduler’ as argument.
so it should look like this:

/httpdocs/bin/grav scheduler

oh, well, I just realized that my proposal will probably not work, as the mentioned script ‘grav’ must be run from the root directory of the grav installation.
this is not a problem for me, as with my hosting, I can run bash shell scripts as scheduled tasks, not only php scripts.
so, the only thing you could try is to write a php script, which calls grav with argument ‘scheduler’ from within your grav install directory.
or, even better, ask your hoster to allow bash shell scripts :smile:

I tried that, changing directory with chdir and excuting bin/grav scheduler with shell_exec. Not sure if it works for the moment, but I’ll post news here.

It works!

<?php
chdir('/xxx/xxx/www');
$output = `/usr/local/php8.1/bin/php bin/grav scheduler -v`;
echo $output;
?>
1 Like