开发者

Executing / running multiple php cron scripts from one cron job

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


Try creating a shell script. Open your text editor and do this:

#!/bin/bash

wget -q /home/XXXXX/domains/domain.co.uk/html/cms/apps/scripts/twitter.php

sleep 5

wget -q /home/XXXXX/domains/domain.com/html/generator/runcrawl.php 

sleep 5

wget -q /home/XXXXX/domains/domain.com/html/generator/runcrawl.php 

This will execute the php script using the wget command in quiet mode. And will add a 5 second pause between scripts.

Save it as any_name.sh and upload it to your server, remember to give execute permission to all the files and add it to your cron job.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜