Skip to content
Advertisement

Update mySQL rows after specified time (PHP, MySQL)

I have a table with users. I want the “status” value of this user to change after some period of time (In months (from 1 to 12)).

For example:
A new row is added with the Name = Jack, Age = 20, Status = enabled, Expiration = 6.

All of this values are sent from a PHP script, when the user registers. A user selects for how many months he wants to be enabled on the website. From 1 to 12. This value is passed into the database (as in example). This user’s status should be changed to disabled after 6 months (Or what ever he has chosen (“Expiration” value)) automatically.

I have read about different techniques that can handle this:

1) Cron (But I guess it can’t be handled on the local server for testing and it requires cPanel. Also I am not sure if I can easily send the expiration value to cron (Please tell me if I am wrong))

2) Set up the event scheduler (I am not sure if it is efficient (Please tell me if I am wrong))

3) Calculation in the PHP script (I guess in this case, if some one with the incorrect time will visit my application, the system will automatically change the status of all of the rows as it looks at the visitors time on their computer (Please tell me if I am wrong))

So basically I am asking “What is the best way to handle this operation in this particular case?” Can you please tell your thoughts about this. I am looking for the most efficient way (As I will probably have a lot of users). Please correct me where I was wrong and I am open to your suggestions. Thank you.

Advertisement

Answer

I think PHP script option suites here(option 3).

you can check for validation at the time of user log in, if that pass the time change the status in database and show user an error.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement