Cyclic execution of a function

Hello! Created functions for generating, receiving, updating, etc. discount cards. Initially there is an array with 12 encoded data. The encoded data contains an id and a lifetime that is set by adding 1 hour to the current one. I want to perform a function that updates the discount card code when the user is sitting in the session. If the function execution loop is not sitting, it stops when the authorization starts. Tell me how to implement this? Or would it be better to use Cron to perform this function?

Hi!

You can either trigger your function each time the installation scripts are executed, for example, on the before_dispatch hook, or you can use cron if you have access to it.

Hi! I tried it through cron, it seems to work, but there are a lot of users and when we run cron every hour, it requires a lot of server resources. Can you suggest a method for checking users, not all at once, but several at a time? To optimize.

I’m afraid I don’t understand the details of what you’re doing and what you’re trying to achieve, so I don’t know what to suggest in this case.

1 Like

Hello. We solved the problem by optimizing the code and functionality logic. It works quickly through Cron. Thank you!

1 Like