从一个 cron 作业执行/运行多个 php cron 脚本
我正在尝试将 PHP 文件设置为 cron 作业,其中该 PHP 文件包含/执行/运行其他 PHP 文件。我正在尝试实现此目标,因为我的主机只允许托管的所有域总共有 5 个 cron 作业,因此我尝试将任务编译到某些 cron 作业中。
我通过 cron 作业本身运行的文件位于
/home/XXXXX/data/cron/tasks/run.php
--
包含文件位于
/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
--
如何包含 run.php 中的配置文件?我尝试过 include_once('/home/XXXXX/domains/domain.co.uk/html/cms/apps/scripts/twitter.php ');
但返回错误。
我也尝试在 run.php 中添加使用以下内容,但没有成功!
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');
--
通过控制面板设置的 cron 作业如下,我知道这是正确的,
php /home/XXXXXX/data/cron/tasks/run.php
我不确定这是否可以通过 shell 脚本轻松完成?有什么想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的有限主机不太可能允许您像这样跨域文件夹,因为这可能是一个安全问题。
如果无法跨目录访问文件,请考虑使用 php 的 cURL 获取初始 cron 作业来调用其他文件。
此方法的缺点是文件必须位于公共 html 目录中。
http://www.php.net/manual/en/ref.curl.php
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
尝试创建一个 shell 脚本。打开文本编辑器并执行以下操作:
这将使用 wget 命令< /a> 处于安静模式。并会在脚本之间添加 5 秒的暂停。
将其保存为
any_name.sh
并将其上传到您的服务器,记住授予所有文件执行权限并将其添加到您的 cron 作业中。Try creating a shell script. Open your text editor and do this:
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.