PHP script called by cron

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Ayashi
Forum Newbie
Posts: 2
Joined: Wed Jan 30, 2008 4:17 am

PHP script called by cron

Post 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.
Ayashi
Forum Newbie
Posts: 2
Joined: Wed Jan 30, 2008 4:17 am

Re: PHP script called by cron

Post 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]."/";
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: PHP script called by cron

Post by pickle »

Untested, but try this:

Code: Select all

$real_path = realpath($_SERVER['SCRIPT_FILENAME']);
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
rsmarsha
Forum Contributor
Posts: 242
Joined: Tue Feb 08, 2005 4:06 am
Location: Leeds, England

Re: PHP script called by cron

Post 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.
Post Reply