Page 1 of 1

PHP script called by cron

Posted: Wed Jan 30, 2008 4:21 am
by Ayashi
hi all,

I'm trying to figure out the base path of a script called by a cron job :

Code: Select all

Zharma scripts # crontab -l
* * * * * /usr/bin/php /home/webroot/scripts/crontab.php >> /home/webroot/scripts/crontab.log
Looking in $_SERVER["PWD"] give me a wrong value. ( /root )

is there a way to figure out the real folder ( /home/webroot/scripts/ )

Kind regards,
Aya.

Re: PHP script called by cron

Posted: Wed Jan 30, 2008 4:58 am
by Ayashi
Found a trick :

Code: Select all

$FileName = $_SERVER["PATH_TRANSLATED"];
$Values   = split("/",$FileName);
for ($i=0;$i<=count($Values)-2;$i++)
 $Path = $Path.$Values[$i]."/";

Re: PHP script called by cron

Posted: Wed Jan 30, 2008 9:57 am
by pickle
Untested, but try this:

Code: Select all

$real_path = realpath($_SERVER['SCRIPT_FILENAME']);

Re: PHP script called by cron

Posted: Wed Jan 30, 2008 10:34 am
by rsmarsha
If you make a file as below:

Code: Select all

 
<?php
phpinfo();
?>
 
And place it in the same folder as the script you want the path for, you'll be able to see the absolute paths and other info.