cron - Running a PHP file from Crontab that includes require_once() -


i'm trying run php file crontab. aim of php send email user. including header files of php framework. crontab seems having problem paths. i've tried changing absolute path.. see test cases below.

using require_once(http://www.test.com/inc/header.php) , running php -f test.php command line results in:

php warning:  require_once(): http:// wrapper disabled in server configuration allow_url_include=0 in /home/user/public/test.com/public/deploy/cron/test.php on line 3 php warning:  require_once(http://www.test.com/inc/header.php): failed open stream: no suitable wrapper found in /home/user/public/trybe-ing.com/public/deploy/cron/test.php on line 3 php fatal error:  require_once(): failed opening required 'http://www.test.com/inc/header.php' (include_path='.:/usr/share/php:/usr/share/pear') in /home/user/public/test.com/public/deploy/cron/test.php on line 3 

using require_once('../../inc/header.php'); , running php -f test.php command line results in php file being carried out successfully.

but looking @ cron tab :

*/1 * * * * php /home/user/public/test.com/public/deploy/cron/test.php 

and looking @ results in /var/mail/, returns error:

message 23: user@server  thu jun 25 13:13:02 2015 x-original-to: user from: root@user (cron daemon) to: chrismoore@ibrahimovic subject: cron <user@server> php /home/user/public/test.com/public/deploy/cron/test.php content-type: text/plain; charset=utf-8 x-cron-env: <shell=/bin/sh> x-cron-env: <home=/home/user> x-cron-env: <path=/usr/bin:/bin> x-cron-env: <logname=user> date: thu, 25 jun 2015 13:13:02 +0100 (bst)  php warning:  require_once(../../inc/header.php): failed open stream: no such file or directory in /home/user/public/trybe-ing.com/public/deploy/cron/test.php on line 3 php fatal error:  require_once(): failed opening required '../../inc/header.php' (include_path='.:/usr/share/php:/usr/share/pear') in /home/user/public/test.com/public/deploy/cron/test.php on line 3 

it seems crontab not able run php file when running command line. how can work?

can see i'm doing wrong , offer solution?

thnnks

try including file it's full path using __dir__ magic constant:

require_once(__dir__ . '/../../inc/header.php'); 

that way, required it's full path , work directory without having change working directory of php file first.


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

android - CollapsingToolbarLayout: position the ExpandedText programmatically -

Listeners to visualise results of load test in JMeter -