Posted by Michael Placentra II on 04/25/07 21:21
roger.moon2@googlemail.com wrote:
> So I wrote a script and at the top it checks whether a file exists
> like below
>
> if (!file_exists("settings.ini"))
> return false;
>
> and the crontab entry:
>
> 00 08 * * 4 /usr/local/bin/php /home/user/scripts/test.php > /dev/null
> 2>&1
>
> however everytime it runs via cron, it can't find the file
> settings.ini because it keeps looking for it in $HOME not in $HOME/
> scripts/ where test.php resides
>
> Why? And how can I re-code it to look in the current directory not in
> $HOME? I tried ./settings.ini but without success
>
You can change the working directory with chdir() near the top of your script:
#!/usr/local/bin/php -q
<?php
chdir( '/home/user/scripts' );
//...
?>
That should make file_exists() work as expected.
If it doesn't do what you want it to do, you can try instead using:
ini_set( 'include_path', '/home/user/scripts' );
To temporarily set it as the (only) include path in the ini settings.
-Mike PII
[Back to original message]
|