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

1 Answer 1

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.

1
  • Thank you for your help, I will go for the database solution. Thanks!
    – C0G1T0
    Feb 3, 2022 at 9:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.