doc1355 Posted October 2, 2021 Share Posted October 2, 2021 I'm developing a website for specific EVENTS. Each EVENT lasts for three months and has fixed start date and end date, and they repeat each year: Event 1: Jan. 1st – Mar. 31st Event 2: Apr. 1st – Jun. 30th Event 3: Jul. 1st – Sep. 30th Event 4: Oct. 1st – Dec. 31st I have two functions FUNCTION 1: should run 3 days before start of the event. FUNCTION 2: should run 1 day before start of last month of the event. Functions should execute only that specific event and not other future or past events. Here how the functions should run for each Event: Event 1: Jan. 1st – Mar. 31st Function 1: on Dec 29 Function 2: last day of Feb Event 2: Apr. 1st – Jun. 30th Function 1: on Mar 29 Function 2: last day of May Event 3: Jul. 1st – Sep. 30th Function 1: on Jun 28th Function 2: Last day of Aug Event 4: Oct. 1st – Dec. 31st Function 1: on Sept 28th Function 2: last day of Nov What I'm doing right now is checking today's date and comparing it to the event date. If event start date is > today and event start date < 3 then run function one. My problem/questions: As of now, I have to remember to execute the functions manually on a specific date. How can I make this automated? Can I execute the function using server Cron job? Will that be a good practice? How would you approach in checking the event date to today? I feel there maybe better way of checking the date to run the function instead of what I'm doing. I hope my question is not vague and makes sense. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/313852-run-function-on-specific-date/ Share on other sites More sharing options...
Barand Posted October 2, 2021 Share Posted October 2, 2021 (edited) Seems like you want eight cron jobs (four for each job) that run on the same date every year. Edited October 2, 2021 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/313852-run-function-on-specific-date/#findComment-1590622 Share on other sites More sharing options...
doc1355 Posted October 2, 2021 Author Share Posted October 2, 2021 (edited) 7 minutes ago, Barand said: Seems like you want eight cron jobs (four for each job) than run on the same date every year. Correct. Is that good practice? Will I be able to secure the function? Only to be run by the cron on my server and admin only? Edited October 2, 2021 by doc1355 Quote Link to comment https://forums.phpfreaks.com/topic/313852-run-function-on-specific-date/#findComment-1590623 Share on other sites More sharing options...
Barand Posted October 2, 2021 Share Posted October 2, 2021 I am not sure just how a cron job can be secured. Any security features may need to be within the functions themselves or the data. Quote Link to comment https://forums.phpfreaks.com/topic/313852-run-function-on-specific-date/#findComment-1590624 Share on other sites More sharing options...
requinix Posted October 2, 2021 Share Posted October 2, 2021 What are these "functions" supposed to do? Quote Link to comment https://forums.phpfreaks.com/topic/313852-run-function-on-specific-date/#findComment-1590625 Share on other sites More sharing options...
doc1355 Posted October 2, 2021 Author Share Posted October 2, 2021 21 minutes ago, requinix said: What are these "functions" supposed to do? It’s a Wordpress site. Functions will create custom posts. Quote Link to comment https://forums.phpfreaks.com/topic/313852-run-function-on-specific-date/#findComment-1590626 Share on other sites More sharing options...
requinix Posted October 2, 2021 Share Posted October 2, 2021 8 minutes ago, doc1355 said: It’s a Wordpress site. Functions will create custom posts. Is the content of each post dynamic? Are posts for past events supposed to remain viewable? Quote Link to comment https://forums.phpfreaks.com/topic/313852-run-function-on-specific-date/#findComment-1590628 Share on other sites More sharing options...
doc1355 Posted October 2, 2021 Author Share Posted October 2, 2021 Each post content is not dynamic. However the function creates many posts at the same time based on some criteria. Old posts will remain visible and accessible. Quote Link to comment https://forums.phpfreaks.com/topic/313852-run-function-on-specific-date/#findComment-1590629 Share on other sites More sharing options...
maxxd Posted October 3, 2021 Share Posted October 3, 2021 If I'm not mistaken you can schedule posts to be published at a specific time in WP. Are you sure you're not over-engineering the solution? Quote Link to comment https://forums.phpfreaks.com/topic/313852-run-function-on-specific-date/#findComment-1590635 Share on other sites More sharing options...
doc1355 Posted October 3, 2021 Author Share Posted October 3, 2021 The script is designed so that it can create hundreds of posts at a specific time. Each post is based on a specific criteria, specific custom taxonomy. I don't think WP can do this. Also the script updates the posts based on some other criteria at a certain time. Quote Link to comment https://forums.phpfreaks.com/topic/313852-run-function-on-specific-date/#findComment-1590636 Share on other sites More sharing options...
gizmola Posted October 6, 2021 Share Posted October 6, 2021 Rather than a number of cron jobs, I would suggest you might want to look at the "At" command in linux. At is a lot like a cron job, however, the jobs are run once from a queue and then removed. You could have one cron job that figures out what jobs need to be queued up with At, and just track and semaphore the At jobs in your php code, using a table to track that they were queued. That allows you to keep a lot of the scheduling in your php code, possibly with some database configuration to give you flexibility. Quote Link to comment https://forums.phpfreaks.com/topic/313852-run-function-on-specific-date/#findComment-1590713 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.