Arpi Patel
Arpi Patel

Reputation: 785

include path error in the cron job in php

i have the functionality to generate XML file on each day using php.

This works fine in the browser.but it doesn't work in the cron job.

The cron give me error for the required once and Fatal error.And it stops the execution of my cron job. the included file is also including other files.

the error which i am getting is like,

Warning: require_once(/common/configs/config_local.inc.php) [function.require-once]: failed to open stream: No such file or directory in /home/wwwsite/public_html/sitename/common/configs/config.inc.php on line 281

Fatal error: require_once() [function.require]: Failed opening required '/common/configs/config_local.inc.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/wwwsite/public_html/sitename/common/configs/config.inc.php on line 281

any one having solution to this issue?

Upvotes: 1

Views: 1457

Answers (2)

Arpi Patel
Arpi Patel

Reputation: 785

i have got the solution,

curl yoursitename/yourfilename.php > /dev/null 2>&1

This has run my cron job as i have set without any error

Upvotes: 1

Alister Bulman
Alister Bulman

Reputation: 35149

It's telling you it can't find '/common/configs/...' note the absolute path there with the first character being a '/'.

You can either make it a relative path from where you are defining it, or put the prefix in there as well ('/home/wwwsite/public_html/sitename/'), maybe with a variable ($sitebase ='/home/wwwsite/public_html/sitename/';) and prefix the include filename with it.

The reason it is working on a website, but not on the command line could be one of a few ways. Most obvious is that the php.ini include_path for the CLI (command line interface) doesn't include the '.' for checking from the current directory. There's also a good reason it doesn't have it by default. The other way is maybe your code puts the ..../sitename/ directory into the include_path - or otherwise sets up the files to be included automatically.

Upvotes: 3

Related Questions