Reputation: 3333
For the past few hours I am struggling to make my cronJobs work. Believe me I googled everything and I even searched on stackoverflow but somehow the code I saw didnt work as expected. This is why I posted here.
I am doing this in SSH :
crontab -e
Then I edit my cronjob list and I add this :
[email protected]
* * * * * wget -q "http://www.mywebsite.com/path/to/cronJob.php"
I get no response on my email with the PHP response. PHP has an output if I call it from browser but I dont get anything on my email, but if I put an error in the cronJob, like removing the last quotes, I get email with the error.
Then I press CTRL+X , I save and then I restart nginx and nothing.
I checked with crontab -l
and the cronjobs are there.
All I want to do is make an URL from my website get executed every 1 minute. If I call the URL from my browser it seems to work.
I have UBUNTU and nGinx
Any help ?
Upvotes: 0
Views: 795
Reputation: 3333
Found the problem. I had this in my code: require_once($_SERVER['DOCUMENT_ROOT'].'/something/cronJob.php').
Apparently $_SERVER['DOCUMENT_ROOT'] was empty.
So I fixed this using :
$path = str_replace('/something/cronJob.php','',$_SERVER['PHP_SELF']);
Upvotes: 1
Reputation: 60037
Here is a few steps to find out what is going wrong:
[email protected]
should be in that script and not in the crontabcrontab
have the same environment variablesUpvotes: 0
Reputation: 121820
Use -O -
.
The problem is that by default, wget will save its result to a file. You want the content to be dumped to stdout.
This means you'll have to cleanup your working directory of all cronJob.php.*
files lying around too ;)
So:
* * * * * wget -q -O - "http://www.mywebsite.com/path/to/cronJob.php"
Upvotes: 4