PHP包含在cron作业中 [英] PHP include in a cron job
问题描述
我试图将PHP文件设置为cron作业,其中的PHP文件包含其他PHP文件。
I'm trying to setup a PHP file as a cron job, where that PHP file includes other PHP files.
文件本身位于/ var / www / vhosts / domain.com / httpdocs / app / protected / classes / cron / runner.php
The file itself is located at /var/www/vhosts/domain.com/httpdocs/app/protected/classes/cron/runner.php
include文件位于
/ var / vhosts / domain.com / httpdocs / app / protected / config.php
The include file is at /var/www/vhosts/domain.com/httpdocs/app/protected/config.php
如何从runner.php包含该配置文件?我试过做require_once('../../ config.php'),但它说的文件不存在。我认为cron从不同的位置或某事运行PHP。
How do I include that config file from runner.php? I tried doing require_once('../../config.php') but it said the file didn't exist.. I presume the cron runs PHP from a different location or something.
cron作业如下。
/ usr / bin / php -q /var/www/vhosts/domain.com/httpdocs/ app / protected / classes / cron / runner.php
/usr/bin/php -q /var/www/vhosts/domain.com/httpdocs/app/protected/classes/cron/runner.php
任何想法?
推荐答案
您的cron应在运行PHP之前更改工作目录:
Your cron should change the working directory before running PHP:
cd /var/www/vhosts/domain.com/httpdocs/app/protected/classes/cron/ && /usr/bin/php -q runner.php
请注意,如果目录不存在,PHP将不会运行runner.php。
Note that if the directory does not exist, PHP will not run runner.php.
这篇关于PHP包含在cron作业中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!