Cron Path Error
I am trying to execute cron but I am getting following errors :
syntax error near unexpected token `"folder/file.php"'
same program I could run if I put URL in browser instead of executing it through server.
When run via the CLI (as a cron job is) relative paths are relative the current working directory, not the directory of the script. Either use an absolute file system path within the script, have the cron job first change directory to that directory, or use chdir() within the script to change to its directory, e.g.:
chdir(__DIR__); // "magic" constant for this file's directory
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
There is an alternative for run php on cron:
- call the site page using wget or curl.
0 8 * * * /usr/bin/wget "http://127.0.0.1/cron.php" > /dev/null 2>&1
0 8 * * * /usr/bin/curl -s "http://127.0.0.1/cron.php"
To the people inside it will feel like an earthquake.
That should knock out the Greco.
And that's your exit strategy.
Always use absolute paths when launching php scripts from cron.
For example :
0 0 * * * /usr/bin/php /var/www/mysite/script.php
To get the absolute path in your cron scripts use the __FILE__ magic variable.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Tags for this Thread