I have several PHP files to be run by cron. I set up the crons using command-
Inside the crontab.txt file, I have written cron commands like this:-
#(Updating tutor activities) - every minute * * * * * /usr/bin/wget -O - -q -t 1 http://project/cron/tutor_activities.php
But none of the functionalities are working (database queries, sending reminder mails etc.). Running the URLs manually works.
Then I put my mail address in
MAILTO and received the mails. In the mail, I received entire HTML source of the page. What is expected in the mail? Why are my functionalities not working?
If I change my cron commands to
#(Updating tutor activities) - every minute * * * * * /usr/bin/wget http://project/cron/tutor_activities.php
Still no success and this comes in my mail -
--15:03:01-- http://project/cron/tutor_activities.php => `tutor_activities.php' Resolving project... IP Address Connecting to test.project|IP Address|:80... connected. HTTP request sent, awaiting response... 301 Moved Permanently Location: http://project./ [following] --15:03:01-- http://project./ => `index.html.1' Resolving project.... IP Address Connecting to project.|IP Address|:80... connected. HTTP request sent, awaiting response... 302 Found Location: http://project/home/ [following] --15:03:01-- http://project/home/ => `index.html.1' Resolving project... IP Address Connecting to wproject|IP Address|:80... connected. HTTP request sent, awaiting response... 200 OK Length: unspecified [text/html] index.html.1 has sprung into existence. Retrying.
And lots of
index.html.2 files are accumulating in the root of my project. I do not want these files to be created. Just want the files to execute.
Same results if I use either of the two commands -
* * * * * /usr/bin/wget http://project/cron/tutor_activities.php * * * * * wget http://project/cron/tutor_activities.php
php command with
MAILTO set sends me this error /bin/sh: php: command not found.
* * * * * php /path/to/test.php
So, I am not able to use
I have written a simple
mailto() inside my test.php. The mail does not come when run through cron (using both
php fails) but running the URL manually works.
To make it clear again, my main problem is that the functionality inside the cron files is not running. Creation of files is a secondary issue.
Any help would be appreciated
I found the problem myself. I did not put the same URL in my crontab file which I was running manually and that was my mistake.
While running manually I was just typing test in the URL, my browsers's list of saved URLs was appearing and I was selecting the URL
http://www.test.project.com/cron/tutor_activities.php, but in the crontab file I had put
http://test.project.com/cron/tutor_activities.php. I was mistakenly assuming this would run
http://www.test.project.com/cron/tutor_activities.php (because we have a rewrite rule present to add
But the rewrite rule was redirecting it to
http://www.test.project.com/home. That's why the HTML content in the mails.
So, the most important thing to learn here is to make sure we don't miss the minute things and don't assume that we did everything correctly. In my case, better to copy-paste the working URL into the cron file.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki