Simple Machines Community Forum

SMF Support => SMF 2.1.x Support => Topic started by: m4z on November 03, 2019, 02:00:08 PM

Title: cron.php cronjob via crontab
Post by: m4z on November 03, 2019, 02:00:08 PM
How is this supposed to be used? Are there any docs?


My usecase: My non-public forum only has a handful of users, and most of them read new posts, post a reply, and then leave, resulting in delayed notifications because they don't stay long enough to trigger the scheduled tasks. More often than not, I was email-notified about new posts only when I visited the site a few hours after others had posted (and triggering the scheduled tasks myself). So I figured I need a real cronjob to push the notifications out regularly.


I've tried different iterations of my setup, and I'm not really happy with the results yet (running the GitHub HEAD of 2019-10-10). (Yet Another Spoiler Mod (YASM) (https://www.simplemachines.org/community/index.php?topic=557848.0) might be causing some or all of my issues.)


So first I tried to run the following from my /etc/crontab (I'm running multiple forums on this host):

* * * * * root /usr/bin/php /home/beta-smf/public_html/cron.php
* * * * * root /usr/bin/php /home/prod-smf/public_html/cron.php


With this, I regularly received error mails about incorrect permissions:

PHP Warning:  file_put_contents(/home/beta-smf/public_html/cache/data_091add6ce6e7029d9f6ea96127b8a529-SMF-modSettings.php): failed to open stream: Permission denied in /home/beta-smf/public_html/Sources/CacheAPI-smf.php on line 108


IIRC, the files were created as beta-smf.beta-smf instead of beta-smf.www-data, but even when fixing the permissions, I kept receiving these errors. (I tried running the cronjob as both the forum user accounts and root, with similar results, IIRC.)
I'm also not sure if the cronjob was the cause of these problems in the first place, or if they just happened when somebody used the forum while the cronjob was running.


I don't remember the 2.5 iterations in between and will skip them; my current setup looks like this:

* * * * * beta-smf  /usr/bin/php /home/beta-smf/public_html/cron.php
* * * * * root      sleep 30; chown beta-smf.www-data /home/beta-smf/public_html/cache/data*; chmod 666 /home/beta-smf/public_html/cache/data*
* * * * * prod-smf  /usr/bin/php /home/prod-smf/public_html/cron.php
* * * * * root      sleep 30; chown prod-smf.www-data /home/prod-smf/public_html/cache/data*; chmod 666 /home/prod-smf/public_html/cache/data*


(cron.php runs for 1-2 seconds, so I assume the 30s offset is not a cause of my problems.)


This seems to work better, but I've got the following issues:
1.) In my Beta forum, despite the identical setup (and the cronjob running successfully every minute), for the second time now I received the following error in the ACP:

No scheduled tasks have been run in the last 24 hours. Re-enabling JavaScript-based method of running scheduled tasks.


The relevant code line is just a broken link, so maybe YASM or another mod is also involved in this:

https://<mydomain>/index.php?https://<mydomain>/


Since the beta forum is only used by myself and much less frequented, I'm suspecting some part of the scheduled tasks isn't run properly, or (blindly speculating what the code does from here on) it silently ends before the "last run" status can be written, or doesn't write it. (The mail notifications, however, work fine.) Since my production forum is apparently used at least daily (just guessing, haven't looked at the logs and I'm only keeping them for 7 days, but it's probable), the problem doesn't happen there.


2.) When I enable YASM, every 6 minutes I receive an error email (probably related thread started by yours truly (https://www.simplemachines.org/community/index.php?topic=569827.msg4032547#msg4032547)):
cron error: The database value you're trying to insert does not exist: smiley_set

Each mail is accompanied by a whopping 10 ACP error log entries:











8: Undefined index: spoiler/home/prod-smf/public_html/Sources/Subs-YASM.php (Zeile 164)
8: Undefined index: YASM_show/home/prod-smf/public_html/Sources/Subs-YASM.php (Zeile 165)
8: Undefined index: YASM_hide/home/prod-smf/public_html/Sources/Subs-YASM.php (Zeile 166)
8: Undefined index: YASM_viewed_by/home/prod-smf/public_html/Sources/Subs-YASM.php (Zeile 177)
8: Undefined index: smiley_set/home/prod-smf/public_html/Sources/Subs.php (Zeile 3237)
8: Undefined index: smiley_set/home/prod-smf/public_html/Sources/Subs.php (Zeile 3250)
8: Undefined index: smiley_set/home/prod-smf/public_html/Sources/Subs.php (Zeile 3261)
The database value you're trying to insert does not exist: smiley_set<newline>Function: parsesmileys/home/prod-smf/public_html/Sources/Subs.php (Zeile 3263)
8: Undefined index: SERVER_PROTOCOL/home/prod-smf/public_html/Sources/Subs.php (Zeile 7076)
The database value you're trying to insert does not exist: smiley_set- (no "file" filter entry)


While most seems to be YASM related, issue 1. and the SERVER_PROTOCOL issue could be core SMF.
Title: Re: cron.php cronjob via crontab
Post by: Arantor on November 03, 2019, 02:03:39 PM
As per your other thread, YASM is a symptom, not the cause. The cause is that cron.php doesn't set up for smiley configuration. I guarantee other mods will be tripped up by this.

SERVER_PROTOCOL is also likely core, making the assumption that the page has been loaded via browser.

The 'database value you're trying to insert does not exist' is usually a fatal error, the issue being that cron.php doesn't define it inside $user_info (something Load.php does when loading the user but that of course does not happen in the cron workflow)
Title: Re: cron.php cronjob via crontab
Post by: m4z on November 03, 2019, 02:08:27 PM
I can't tell you enough how awesome you are! <3 <3 <3 <3 <3

(I'd also add how quick you are, but that could be misconstrued. ;))
Title: Re: cron.php cronjob via crontab
Post by: m4z on November 10, 2019, 01:38:48 PM
Reported as https://github.com/SimpleMachines/SMF2.1/issues/5868