Include issues with Cron Jobs

Status
Not open for further replies.

chewett

New Member
Messages
137
Reaction score
0
Points
0
Im currently using a cron job to run a script each time, So far so good.

It runs the script using the following cron command

PHP:
/usr/bin/php   /home/chewett/public_html/dir/file.php >>/home/chewett/public_html/cronlog.txt  2>&1

But the problem occurs when my file is run, because i have includes in the file.

I am trying to include

/home/chewett/public_html/dir2/file2.php using include($_SERVER['DOCUMENT_ROOT'] . "/dir2/file2.php")

But it always says it cannot find the file. I found a very old topic sugesting to cd to the root of my directory, but after trying this still get the same error

I hope someone can advise me how i should call the command, or how my includes should be set up.

Also, to clarify the script works perfectly fine when run normally

Thanks for any help you might give! +rep for usefulness :)
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
Could you cut/paste the exact error message that shows up in the log?
 

chewett

New Member
Messages
137
Reaction score
0
Points
0
Current Cron Command

PHP:
/usr/bin/php   /home/chewett/public_html/SoE/curl/get_logs.php >>/home/chewett/public_html/cronlog.txt  2>&1

Error:

PHP:
X-Powered-By: PHP/5.2.14
Content-type: text/html

<br />
<b>Warning</b>:  require_once(/curl/curl.php) [<a href='function.require-once'>function.require-once</a>]: failed to open stream: No such file or directory in <b>/home/chewett/public_html/SoE/curl/get_logs.php</b> on line <b>8</b><br />
<br />
<b>Fatal error</b>:  require_once() [<a href='function.require'>function.require</a>]: Failed opening required '/curl/curl.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in <b>/home/chewett/public_html/SoE/curl/get_logs.php</b> on line <b>8</b><br />

my include statement is

PHP:
require_once($_SERVER['DOCUMENT_ROOT'] . "/curl/curl.php");


Hopefully there is either a different way i can code my includes, or an addtional part of my cron to call, I was trying to use.

cd /home/chewett/public_html ; + the above command but that didnt seem to help either

If the script runs successfully it should output something like

Got logs at :2011_04_30_22_33

which it does when visiting the page normally.
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
require_once("/home/chewett/public_html/curl/curl.php");

OR

require_once("../curl/curl.php");

Unless I am wrong, the $_SERVER['DOCUMENT_ROOT'] is only set if script is run via the Web (document root is a web server concept)

Not sure if there is another super-global that you can use from the command line. I will run a few tests and see.
 

chewett

New Member
Messages
137
Reaction score
0
Points
0
thanks, both of them got it working, closed
 
Last edited:

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
$_ENV[ 'PWD' ] will give you '/home/chewett' (since it is running in your 'home directory' ). That is the best I could find for either $_ENV or $_SERVER ( $_ENV['PHP_SELF'] shows as not being set on my test account ).
 
Status
Not open for further replies.
Top