最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

wp cron - Email alert with wp_cron and wp_mail if new data (external API) - Pseudo code

programmeradmin2浏览0评论

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 badges
Add a comment  | 

1 Answer 1

Reset to default 0

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.

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.

发布评论

评论列表(0)

  1. 暂无评论