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

Yes, you can use SMF functions in a cron script inside /Sources—just make sure to include SSI.php or index.php to load SMF properly.

If it's only run via CLI, you don't need the !defined('SMF') check. Instead, you can add php_sapi_name() === 'cli' to limit access to the command line.

Advertisement: