Cronjob inside folder Sources

Started by Jotade29, April 15, 2025, 09:35:52 PM

Previous topic - Next topic

Jotade29

SMF: 2.0.19
Hi, I've created a modification that modifies the user's XML download. I don't want to go into details, but from a panel, it allows me to have it appear when the user requests their personal data. When i accept it, a date is saved in the DB. After 48 hours, I want that approval to be automatically deleted. To do this, I thought about creating an event in phpmyadmin, but since my host is shared and I use cPanel, I have to use a cronjob...

My question is: can I use the SMF functions to connect to the database for that cronjob if i create the cronjob inside folder /Sources? And second, I will only access that cronjob through the CLI, that is, from the automatic call to that cronjob every 48 hours, which will open that PHP file, which I will save in the forum's source folder. Should I use if->!defined(SMF)...-> hacking attempt here, or should I use a different method to access it exclusively through the CLI?

Thnxx
Quote from: Diego Andrés on August 12, 2023, 02:20:18 AMI'm afraid convincing Jotade to upgrade to SMF 2.1 will require bigger effort than your work sanitizing Unicode characters  :laugh:

All Colours Sam

You can use a cronjob sure but SMF 2.0 also provides its own scheduled task system, its not exactly a replacement for a cron since it relies on user activity (your forum needs to be requested for the scheduled task job to run).

However, you can use a cron that points out to SMF's scheduled system, that way you can guarantee that the event will be executed at the exact time you need, there was a guide somewhere here about setting up a cron job with SMF's scheduled system and theres also some documentation about how to add a new task to it as well.
Oh, wouldn't it be great if I *was* crazy? ...then the world would be okay
Suki

pimps

Thanks for the info, @All Colours Sam. I'm also trying to handle something time-sensitive, so relying solely on user activity might not work for me. If I create a real cronjob that hits SMF's cron.php, will that ensure the scheduled task runs on time even with no forum visits? Also wondering if there's a clean way to trigger just one specific task that I've added. If you have the link to that guide you mentioned, I'd appreciate it.

Sesquipedalian

Quote from: pimps on June 04, 2025, 10:43:07 PMIf I create a real cronjob that hits SMF's cron.php, will that ensure the scheduled task runs on time even with no forum visits?

Yes.

QuoteAlso wondering if there's a clean way to trigger just one specific task that I've added.

No, but if you set your cronjob to run fairly frequently, there's no need to worry about that. SMF's internal queue is quite efficient. Your task will be completed promptly.
I promise you nothing.

Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

shawnb61

Note this forum is 2.0.

I know this works fine with 2.1 - after fixes.

I haven't seen it work on 2.0. 

As ever, I strongly suggest upgrading to 2.1.
A question worth asking is born in experience & driven by necessity. - Fripp

Sesquipedalian

Quote from: shawnb61 on June 05, 2025, 12:13:22 AMNote this forum is 2.0.
Oops. I overlooked that part.

Quote from: shawnb61 on June 05, 2025, 12:13:22 AMAs ever, I strongly suggest upgrading to 2.1.
100%
I promise you nothing.

Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

All Colours Sam

#6
Quote from: shawnb61 on June 05, 2025, 12:13:22 AMNote this forum is 2.0.

I do remember there was a guide or something related to how to configure a cronjob with SMF 2.0 will try to search for it, might need some adjustments due to longevity but could serve as reference.


Another possibility is to configure a cronjob that will hit the forum's index and that should trigger the scheduled system
Oh, wouldn't it be great if I *was* crazy? ...then the world would be okay
Suki

Advertisement: