Reputation: 1
I've spent days still can't figure out this.
I have following file structure under public_html:
cron_jobs/file.php contains - > include('../base/basefile.php')
base/basefile.php contains - > include('baseSubFile.php')
when I run
/pathtophp/php -f ~/public_html/cron_jobs/file.php
it works ok but when I copy the same command to cron in cpanel, I get error saying
'basesubfile.php' can't be found
Please help.
Upvotes: 0
Views: 676
Reputation: 788
Simply put this at the top of your PHP script:
chdir(dirname(__FILE__));
Upvotes: 0
Reputation: 17314
You should used
include dirname( __FILE__ ) . '/../base/basefile.php';
and
include dirname( __FILE__ ) . '/baseSubFile.php';
The function dirname returns parent directory's path
Upvotes: 1
Reputation: 70517
Cron won't run from the same directory as your php file is in, so you'll need to change to it first:
cd /home/user/public_html/cron_jobs/ && /pathtophp/php -f file.php
I recommend the full path versus ~
when dealing with cron scripts to avoid confusion
Upvotes: 2