I have a PHP script that works fine when run from the browser, but when run as a cron job (which was set up via cPanel), it doesn't. The server is running Linux.
I've narrowed it down to an include statement:
$include_path = dirname(__FILE__) . "/";
$wpconfig = $include_path . 'blog/wp-config.php';
include($wpconfig);
I've also tried using realpath(dirname(FILE)) instead of just dirname(FILE), and just trying to include "blog/wp-config.php", but it makes no difference.
The PHP script resides in this folder:
/home2/USERNAME/public_html/DOMAIN/tools/
The file I need to include is in this folder, which is one level below the one where the PHP script resides:
/home2/USERNAME/public_html/DOMAIN/tools/blog/wp-config.php
I thought using an absolute path should work in a cron job, but apparently not.
I'm clearly doing something wrong (or stupid), so could someone please put me out of my misery and point me in the right direction.
Thanks!
requireinstead ofinclude, because it will throw an error if including fails. Maybe that error will give some insights. 3. it might be a rights issue. If the user running the script doesn't have read rights on the directory or file, then including will fail. - GolezTrol