Question

Hi there I'd like to make a recurring event based on calendar basis. The thing I want to ask is this: How to trigger the event? If the client doesn't login or open the webapp to trigger the event in the constructor, how do I make the code to run anyways.

I know cron jobs maybe the solution, but is there any other solution?(I want to avoid cron jobs).

Était-ce utile?

La solution 2

If that job should be triggered to keep the server in a good state, it should be run using a cron job, if its a database management, the database manager have the event's table to make cron jobs, if it's needed for only for the user, it can be a workload safe if you just don't do it until user login. You can manually login to trigger the event too, to an admin page maybe.

Autres conseils

You have to have something running in order for this to work; a cron is ideal for this, as it can run a script at regular intervals to check for things like events.

Without that, you are left by this being triggered by user action, but like you said, that user might not always log in to trigger it.

You could modify your code to have any user trigger actions for all users. It's a little more complex, as you'd need to allow for multiple users logging in at the same time when you only want one of them to trigger stuff. I would set up a table in your database to keep track of the last time things were triggered, and then if the gap since then and now is large enough when a user logs in, add a new entry in the table with the time now to prevent another user triggering this, and trigger the bits you need to run.

Like I said though, this won't be a perfect solution, and I really would recommend using cron. Is there any reason why you want to avoid using cron?

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top