You are here: Re: PHP and Crontab and Current Directory « PHP Programming Language « IT news, forums, messages
Re: PHP and Crontab and Current Directory

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация