I would like to check twice daily if there is some new data published and send me an email if this is the case. In pseudo code here what I thought I could do:
- Get new list of movies (external API request)
- Get old list of movies (stock somewhere but how?)
- Compare the two list Send email with wp_mail
- Update content of old list for the next time (how?)
- Repeat process twice daily with wp_cron
My problem is that I don't know how and where to stock the previous list of movies? I thought about a global variable that I could call in the function but from what i red so far, it seems that it is always better to avoid global variable? Also I don't know if it is possible to update the global variable for the next task.
Any idea about how to manage the list or maybe a different approach?
Thank you for your help
I would like to check twice daily if there is some new data published and send me an email if this is the case. In pseudo code here what I thought I could do:
- Get new list of movies (external API request)
- Get old list of movies (stock somewhere but how?)
- Compare the two list Send email with wp_mail
- Update content of old list for the next time (how?)
- Repeat process twice daily with wp_cron
My problem is that I don't know how and where to stock the previous list of movies? I thought about a global variable that I could call in the function but from what i red so far, it seems that it is always better to avoid global variable? Also I don't know if it is possible to update the global variable for the next task.
Any idea about how to manage the list or maybe a different approach?
Thank you for your help
Share Improve this question asked Feb 2, 2022 at 17:14 C0G1T0C0G1T0 1053 bronze badges1 Answer
Reset to default 0My problem is that I don't know how and where to stock the previous list of movies? I thought about a global variable that I could call in the function but from what i red so far, it seems that it is always better to avoid global variable? Also I don't know if it is possible to update the global variable for the next task.
You better use a persistent memory, because your variable will die when a PHP script finishes its work. So you can store the old list somewhere in the database or in a special file.