PHP: Require path does not work for cron job?

前端 未结 6 1313
后悔当初
后悔当初 2020-12-05 13:44

I have a cron job that needs to include this file:

require \'../includes/common.php\';

however, when it is run via the cron job (and not my

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-05 14:41

    nono. you need to use absolute paths on crons.

    what I do is:

    // supouse your cron is on app/cron and your lib is on app/lib
    $base = dirname(dirname(__FILE__)); // now $base contains "app"
    
    include_once $base . '/lib/db.inc';
    
    // move on
    

提交回复
热议问题