1

I have a php script that triggers some magento actions, and I set it to a cron of:

cd /home/dir/public_html; php -f file.php;

This starts the script, however it does not finish executing for some reason, the cron runs as the user "user", and when I run the command from the terminal as root it works perfectly. All the files it uses are chowned to user however. I thought it was an issue with paths which is why I added the CD command to the front of it, however that wasn't it.

I'm thinking this may be an issue with the creation of a lock file, I have it create a lock file, run the script, then delete the lock file in order to prevent it from running if it already is. The lock file is generated but never deleted, my knowledge is if it creates it as user "user" then it should be able to delete it as that user as well.

Any thoughts? Much appreciated.

4
  • It may be bombing out before reaching the "delete the lockfile" section. I'd suggest adding some debug output to the various stages. "doing this", "doing that", "attempting something", etc... Commented Nov 7, 2011 at 17:29
  • Can you create/delete the lockfile as the 'user' via terminal command line? Commented Nov 7, 2011 at 17:29
  • I think you may have found the issue, the "user" does not have shell access. Well, that was a silly question. Commented Nov 7, 2011 at 17:32
  • possible duplicate of How can I force PHP Version for Command Line? Commented Nov 7, 2011 at 17:33

2 Answers 2

3

Try to put the full path of PHP, or define the PATH variable in the first lines of crontab:

PATH=/usr/local/bin:/usr/bin:/bin:/usr/games:/sbin:/usr/sbin

Edit : moreover, you can log your script like that :

* * * * * cd /home/dir/public_html; /usr/bin/php -f file.php; &>/tmp/file.log
Sign up to request clarification or add additional context in comments.

Comments

1

Instead of calling the php from within the cronjob, call a shell script which is calling the php file then.

You can then change the environment the script is running in w/o the need to change the cronjob and you can easier test-drive the cron command (as you can just call the shell-script).

You can then, in the shell script, change the directory where the php-script expects to be in which will most certainly solve your issue.

Additionally you can change ini directives, handle logging and shell error handling, like piping STDERR to a file etc.

This is not exactly your problem, but the information given in this question might solve your issue: How can I force PHP Version for Command Line?.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.