I'm having some issues with the cron hook in a module. The hook is supposed to do one simple thing: Update database records that meet very simple criteria, and do so daily. I have the cron job set up on my server, and I know that cron works because I have other cron jobs that run daily (at different times), and the work just fine. They are not drupal cron jobs, just some other processing I have set up.
I thought that maybe I had an error in a query and that was killing the cron hook before it had the chance to work it's magic. So I wrote another file and stuck those queries in it. They work just fine. Something is up with my cron setup within drupal. I didn't do anything weird when I first installed Drupal. I'm running 5.5, and I got that status report message when I first installed, telling me that cron had not run. If I remember correctly, I was given only one option, to run cron manually, and so I clicked that. If this is causing the problem, let me know.
Though I'm not sure it is. It seems to me that cron was working at some point. When I was first developing this module, I'm pretty sure that it worked. Though, there is a slim chance that it worked in my head from a "thought experiment" perspective. And the logic does work flawlessly (I have just confirmed).
Anyone know why the cron wouldn't be firing? One other thing... if I just run the cron.php file from my browser, the cron hook is not called because none of the processing takes place. Clearly, something is wrong. Help.
Comments
How have you configured cron?
You must use some way to trigger cron in Drupal. Do you have crontab, and does it include something like
Drupal doesn't do anything with cron by itself. It needs an outside service to trigger it.
Yes...
Yeah, cron runs on the server just fine. I have it set up to run daily, like I said, with some other jobs, but the module cron hook is not firing. I have my server email the results of each cron run, and here's what the drupal cron sends me (I have heard this is normal, but maybe I heard wrong):
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent in /home/lassonet/public_html/includes/bootstrap.inc on line 899
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/lassonet/public_html/includes/bootstrap.inc:899) in /home/lassonet/public_html/includes/bootstrap.inc on line 899
Thanks,
Caleb
http://www.cube-escape.com
Some more information
I did a little digging into my drupal install. First of all, I can't type or count, because it's Drupal 5.6 and not 5.5. But that's probably not the problem here. I went to my admin area and to my status report pages. I saw something that looked odd.
There is a green check mark next to "Cron maintenance tasks," telling me that it's all good. Well, in the details column, drupal tells me that cron was last run 8 weeks ago. And then there's a link telling me I can run cron manually. I'm going to click that link and try to set that up (even though I thought I had already done that). Does this new information shed any light on my cron situation?
Thanks,
Caleb
http://www.cube-escape.com
More digging has unearthed
More digging has unearthed more questions...I guess.
I checked watchdog and saw that one of my cron functions had an unknown column error. So, I looked at that function and there was a typo in the first query of that function. I fixed it and ran cron manually in my browser with /cron.php. I went back and checked the watchdog logs and it says that cron exceeded its time limit and was aborted. Maybe I've got some infinite loop somewhere? I've got several modules running a cron hook, but each function is rather simple. Stuff like expiring coupons that are too old, and similar.
On another note, something odd does happen when I run cron.php manually from my browser. When it is finished (aborted, broken, whatever), it takes me to quite an odd place. I end up on a page of one of my custom modules -- a module that has no cron hook. But it takes me to that page every single time I run cron.php in my browser, and has done so for as long as I can remember.
I don't know if any of this helps.
Thanks,
Caleb
http://www.cube-escape.com
Weird!
OK, I just went through all of my custom modules and commented out all of the cron hooks. /* function to }*/...completely removed from the module functionality. Then I hit up cron.php in my browser. Not surprisingly, I ended up on that page of a custom module that has no cron hook. No surprise there, since it's been doing it for a long time. Then, I went back to my watchdog logs and I'm still getting that time limit exceeded so cron is aborting message.
Something strange is going on. Anyone know anything at all (anything regarding this issue, not, for example, the color of your socks)?
Thanks,
Caleb
http://www.cube-escape.com
My only advice
When you trigger cron, you run not only your module cron hooks but the cron jobs of Drupal core. This includes indexing search and removing old log records. Can you see if either gets done? If it does, then your log history should be cleared to a point a week ago, or whatever you have that setting on, and you should be able to find cron messages also, saying "Cron run completed".
The thing to try is increasing PHP memory. I used to suffer from a blank page syndrome on the module page, since PHP ran out of memory. If cron.php does the same, it could explain why nothing seems to happen.
I thought that the memory
I thought that the memory and execution times might be the problem, but I doubt that it is. Something was causing issues a few months ago, so I increased the max_execution_time to 180 and the memory_limit to 40M. The funny thing is, that when I run cron manually by hitting cron.php in my browser, the time it takes to go to the page I mentioned above (the one from the module with no cron hook), it's like nothing is happening. Instead of some processing going on, it's like I just clicked a link to go to that page.
Right now, on my "Status" page, the system shows that cron last ran successfully 9 weeks and 9 hours ago. I have cron set up to run daily...
My log entries for watchdog go back to 5/19/2008, which, I believe, is when I first installed this last version of the site.
It looks like cron is not running at all. Does anyone know what is causing this? I don't see a cron admin page within drupal, so I'm guessing this is all just taken care of automatically. I've had cron set up to run daily for several weeks now. I'm guessing 9 weeks and 4 hours ago.
Help!
Thanks,
Caleb
http://www.cube-escape.com
Anyone have any idea why the
Anyone have any idea why the drupal cron is not running?
Thanks,
Caleb
http://www.cube-escape.com
Maybe 5.x has a problem with
Maybe 5.x has a problem with cron and needs to be patched? I'm at a loss here. My crontab functions -- I've got other cron jobs that run just fine. But no matter what I do, I can't get drupal's cron to fire.
Help!
Thanks,
Caleb
http://www.cube-escape.com
Help!
So... does anyone have any ideas why drupal's cron hook is not firing? Other cron jobs that I have manually set up on my server run just fine, so it's not the machine. It's drupal, but I don't know what or how. So I can't really fix it...
Thanks,
Caleb
http://www.cube-escape.com
I have the same problem!
I have the same problem! it's driving me insane! i needed the hook cron to change a workflow state, so i implemented... but didn't work... so i tried something more simple and came to the conclusion that it just DID NOT WORK.... ¬¬' some help please
just tried to run the
just tried to run the function that implements the hook (mymodule_hook) directly... and it works... i mean i just created a new page node with php input format and executed the function mymodule_cron and efectivly works... but it doesn't work when i run cron
^^' .... nop... lieing... a
^^' .... nop... lieing... I have no such problem... my problem is that i'm a %&$#@.... i had my function name wrong... i misspelled my module name... check that chaoscube just in case you're as %&#$@ as i am XD
PHP errors
This is almost always because another module is causing cron.php to stop. Start picking through PHP/Apache logs and Drupal's watchdog looking for hook_cron errors.
--
https://www.codeenigma.com/