Trouble with scripts when using cron

software development


I wrote a script in php that references another file in another folder. In order to access the file, I am referencing it as “…/file.txt”. When I manually execute the script myself, everything works. However when the cronjob executes, I receiver an error:

Warning: main(…/file.txt): failed to open stream: No such file or directory in /home/.loadie/xyz/ on line 3

In my cronjob, I am executing this line while using the web panel tool:

/usr/local/bin/php /home/xyz/

Any help would be appreciated.


Does /usr/local/php5/bin/php /home/xyz/ work?

CEO Norm

Opinions are my own views, not DreamHosts’.
I am NOT a DreamHost employee OK! :@

Act on my advice at your own risk!


instead of …/file.txt (which is probably not starting from the directory you expect it to), try something like:

dirname(dirname($_SERVER[‘SCRIPT_NAME’])) . ‘/file.txt’

the two dirname()s handle removing /script.php and then /files from the end of /home/xyz/

track7 - my dream-hosted site


dirname(dirname($_SERVER[‘SCRIPT_NAME’])) . ‘/file.txt’ did not work, but clearly was on the right track. Instead of using a relative path name, I just changed it to an absolute path name. I assume there is a more elegant way of doing it with system variables, but as long as it works…