I’m trying to setup a PHP file as a cron job, where that PHP file includes/executes/runs other PHP files. I am trying to achieve this because my host only allows 5 cron jobs total for the all the domains hosted, so I’m trying to compile tasks into certain cron jobs.
The file i’m running via a cron job itself is located at
/home/XXXXX/data/cron/tasks/run.php
—
The include files are at
/home/XXXXX/domains/domain.co.uk/html/cms/apps/scripts/twitter.php
/home/XXXXX/domains/domain.com/html/generator/runcrawl.php
/home/XXXXX/domains/domain.net/html/cms/apps/scripts/sitemap.php
—
How do I include that config file from run.php? I’ve tried doing include_once('/home/XXXXX/domains/domain.co.uk/html/cms/apps/scripts/twitter.php '); but returned errors.
I have also tried adding using the following in the run.php but no luck!
exec('php /home/XXXXX/domains/domain.co.uk/html/cms/apps/scripts/twitter.php');
exec('php /home/XXXXX/domains/domain.com/html/generator/runcrawl.php');
exec('php /home/XXXXX/domains/domain.net/html/cms/apps/scripts/sitemap.php');
—
The cron job setup through the control panel is the following, which I know is correct
php /home/XXXXXX/data/cron/tasks/run.php
I’m not sure if this could be easily done via a shell script instead? Any thoughts please?
It’s unlikely your limited host will allow you to cross domain folders like that as it can be a security issue.
If you cannot access files across directories, then consider getting the initial cron job to call other files using php’s cURL.
The downside of this method is that the files must be in the public html directory.
http://www.php.net/manual/en/ref.curl.php