Uutiset:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu
Advertisement:

What triggers Scheduled Tasks?

Aloittaja Krashsite, heinäkuu 06, 2013, 03:15:32 IP

« edellinen - seuraava »

Sir Osis of Liver


Looks like they're run from Load.php calling ScheduledTasks.php, which would mean they rely on users hitting the forum to initiate the tasks. 

Is that how it works?

When in Emor, do as the Snamors.
                              - D. Lister

vbgamer45

Yes it replies on a vistor to view the forum to run the task.
Community Suite for SMF - Grow your forum with SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com - Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

Sir Osis of Liver


I need to run a task at an exact time (last second of the month), preferably without using a cronjob, so that php script initiates the event.  Any way to do this?

When in Emor, do as the Snamors.
                              - D. Lister

MrPhil

The scheduled tasks, as you know, are kicked off by someone visiting the forum. If you need to run something at a precise time, you can't count on someone happening to visit at exactly the right time. What is the objection to using a cron job? The first thing you might try is kicking off some forum activity at the desired time, using "wget" or the like. I'm not sure what activities will trigger the scheduled tasks, but you could try something as simple as viewing a topic. Depending on just what you want to do, it might even be easier to run it directly via a cron job (either an SMF URL or a custom-written PHP script).

I don't think cron is very flexible about knowing the "last day of the month", so you may have to kick off the cron job daily from the 28th through the 31st, and let SMF's scheduling decide which day to run on. Or, a PHP script can figure out whether it's the last day of the month.

Windows has its own Scheduled Tasks function, if you're on a Windows server. I understand that it's quite similar to cron.

Sir Osis of Liver


I'm trying to keep everything inhouse.  Most of the low-end shared hosts are pretty crappy, and a cronjob would rely entirely on server reliability, so I'm not real comfortable with that.  Think I got my answer here.  Unfortunately there's really no way to test it, except to run it live on a production forum. :P

When in Emor, do as the Snamors.
                              - D. Lister

emanuele

Lainaus käyttäjältä: Krash. - heinäkuu 08, 2013, 12:33:04 AP
and a cronjob would rely entirely on server reliability
???

Sorry, but if the server is not reliable enough to run a cronjob...how can it be reliable to run anything?

To run a cronjob you have to rely on the server (hardware) and on the OS.
To run a pseudo-cronjob from php you have to rely on: server (hardware), OS, apache, php, a visitor, (optionally javascript), and in between of all that the net itself.

How can the second be more reliable?

First: why do you need the cron to be run *exactly* at the end of the month? And not 1 second after that?


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

Sir Osis of Liver


Haven't used cronjobs this way, and it's easier for me to handle errors if everything is done by the php (I understand it better). 

Members see a countdown to end of month (days/hours/minutes/seconds), when it reaches 0 a member is randomly selected, saved to db, and displayed in a popup, and everything resets for next month.  The idea is for members to be able to view the selection process, so it has to happen when the counter reaches 0.  The code works (so far) - it's just a question of finding the best way to trigger the selection so it's coordinated with the countdown, and only happens once.

When in Emor, do as the Snamors.
                              - D. Lister

IchBin™

cronjob is simply the most reliable method you will find. If a host doesn't have that, they are not worth paying them for hosting. Every single host should have access to cronjobs through their cpanel. It's about the only way you'll be able to reliably hit a script at a specific time without user interaction. Otherwise you are relying on outside sources to hit your script at a specific time.

Instead of doing it at midnight of the last day of the month, you can do it on the first day of the month at 1 second after midnight. In cron there's no way to specify the last day of the month since months don't all end on the same day (28,30,31). So doing it on the first day is the way to go IMO.
IchBin™        TinyPortal

MrPhil

So if anyone happens to be signed on to your forum, they'll see the countdown (Javascript?) at the correct time. At 0 and not a second sooner or later, you need some code to run to do something (involving saving a selection to the database). Then the GUI reaches into the database and shows a popup or other display.

No reason to have to run the selection code attached to the countdown/display code. Run the selection off a cron job at precisely the instant you choose. The GUI can then reach into the database and get the selected member. You are aware you can run PHP code from the command line (cron)? Just make sure the cron job has been allowed enough time to run, plus a half second or so for clock skew, before you try to grab the value. Make the GUI robust enough that it can wait a quarter second or so and try again, if the value wasn't there.

It is possible to do the last day of the month, but requires you to run every day from the 28th through 31st and pick just one of those days.

Sir Osis of Liver


I've considered making the selection a minute or so into the first of the next month.  Php seems to give me the exact end of month with -



$last_minute = mktime(23, 59, 0, date("n"), date("t"));



This gives me time remaining -



$remaining = $last_minute - time();



- which is passed to the javascript, which runs the counter down to 0 and calls the php script to select the member and save to db.  Works fine with just one member (me) viewing the countdown.  Can't think of a way to simulate multiple viewers, so I'm working blind here.  Ricky suggested locking the table after the first pick is made, but that may cause other problems.

Don't have any info yet on the host situation for the forum I'm doing this for, but did a quick search on my host, and nothing comes up for 'cron job' or 'scheduled task'.  Put in a support ticket and I'll see what comes back. Need to play with it to see how it works in with what I've got.

When in Emor, do as the Snamors.
                              - D. Lister

Advertisement: