Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

General

Add Grav scheduler as a php script

Solved by nix View solution

Started by nix 3 years ago · 4 replies · 1023 views
3 years ago

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:

TXT
(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?

3 years ago

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:

TXT
/httpdocs/bin/grav scheduler
3 years ago

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 😄

3 years ago

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.

3 years ago Solution

It works!

PHP
<?php
chdir('/xxx/xxx/www');
$output = `/usr/local/php8.1/bin/php bin/grav scheduler -v`;
echo $output;
?>
👍 1
last edited 12/01/23 by nix

Suggested topics

Topic Participants Replies Views Activity
General · by Jerry Hunt, 4 days ago
2 85 13 hours ago
General · by pamtbaau, 18 hours ago
1 60 17 hours ago
General · by Andy Miller, 1 day ago
0 47 1 day ago
General · by Marcel, 12 months ago
6 350 5 days ago
General · by Duc , 6 days ago
3 44 5 days ago