Some difficulty with file_exists
So I wrote a script to run via crontab but when it tries to check
whether a file exists like below:
if (!file_exists("settings.ini"))
return false;
it checks whether the file exists in $HOME not in /home/user/files/
scripts/ where the original file is been executed from:
00 20 * * 1 /usr/local/bin/php /home/user/files/scripts/check.php > /
dev/null 2>&1
Why is that?
Re: Some difficulty with file_exists
roger.moon2 [at] googlemail.com wrote:
> So I wrote a script to run via crontab but when it tries to check
> whether a file exists like below:
>
> if (!file_exists("settings.ini"))
> return false;
>
> it checks whether the file exists in $HOME not in /home/user/files/
> scripts/ where the original file is been executed from:
>
> 00 20 * * 1 /usr/local/bin/php /home/user/files/scripts/check.php > /
> dev/null 2>&1
>
> Why is that?
Because you use the CLI, not the (web)server variant? The current
working directory is the directory from which /usr/local/bin/php is invoked.
So, for instance on the `doze box here:
-- C:\cwd.php ---
echo getcwd();
--------------
C:\>"C:\PHP\php.exe" "C:\cwd.php"
C:\
C:\>cd FOO
C:\FOO>"C:\PHP\php.exe" "C:\cwd.php"
C:\FOO
If it's terribly important that the working directory is the same as
where your file resides you can add something like this to it:
chdir(dirname(__FILE__));
HTH,
--
Rik Wasmus
Estimated date being able to walk again: 01-05-2007.
Less then a week, hurray!
Re: Some difficulty with file_exists
roger.moon2 [at] googlemail.com wrote:
> So I wrote a script to run via crontab but when it tries to check
> whether a file exists like below:
>
> if (!file_exists("settings.ini"))
> return false;
>
> it checks whether the file exists in $HOME not in /home/user/files/
> scripts/ where the original file is been executed from:
>
> 00 20 * * 1 /usr/local/bin/php /home/user/files/scripts/check.php > /
> dev/null 2>&1
>
> Why is that?
Because you use the CLI, not the (web)server variant? The current
working directory is the directory from which /usr/local/bin/php is invoked.
So, for instance on the `doze box here:
-- C:\cwd.php ---
echo getcwd();
--------------
C:\>"C:\PHP\php.exe" "C:\cwd.php"
C:\
C:\>cd FOO
C:\FOO>"C:\PHP\php.exe" "C:\cwd.php"
C:\FOO
If it's terribly important that the working directory is the same as
where your file resides you can add something like this to it:
chdir(dirname(__FILE__));
HTH,
--
Rik Wasmus
Estimated date being able to walk again: 01-05-2007.
Less then a week, hurray!
Re: Some difficulty with file_exists
roger.moon2 [at] googlemail.com wrote:
> So I wrote a script to run via crontab but when it tries to check
> whether a file exists like below:
>
> if (!file_exists("settings.ini"))
> return false;
>
> it checks whether the file exists in $HOME not in /home/user/files/
> scripts/ where the original file is been executed from:
>
> 00 20 * * 1 /usr/local/bin/php /home/user/files/scripts/check.php > /
> dev/null 2>&1
>
> Why is that?
>
When using as CLI program, the ./ is the location from where the file is
executed, in your example it's the cron users home directory that would most
likely be ./, so the solution for your problem is to use absolute path.
if (!file_exists("home/user/files/scripts/settings.ini"))
return false;
Things are different if you execute the script via a web server, but absolut
paths will always work.
--
//Aho
Re: Some difficulty with file_exists
roger.moon2 [at] googlemail.com wrote:
> So I wrote a script to run via crontab but when it tries to check
> whether a file exists like below:
>
> if (!file_exists("settings.ini"))
> return false;
>
> it checks whether the file exists in $HOME not in /home/user/files/
> scripts/ where the original file is been executed from:
>
> 00 20 * * 1 /usr/local/bin/php /home/user/files/scripts/check.php > /
> dev/null 2>&1
>
> Why is that?
>
When using as CLI program, the ./ is the location from where the file is
executed, in your example it's the cron users home directory that would most
likely be ./, so the solution for your problem is to use absolute path.
if (!file_exists("home/user/files/scripts/settings.ini"))
return false;
Things are different if you execute the script via a web server, but absolut
paths will always work.
--
//Aho