Presently, I am using a website. This site is written using PHP with PostgreSQL because the back-finish. For that server I personally use Apache (XAMPP). This site includes a membership feature contain free membership and premium membership. Premium membership valid for 12 months following the registration, next the consumer membership is going to be revert to free membership. To become a premium membership again, the consumer should spend the money for membership fee and also the account is going to be upgraded again for the following 12 months (imagine Rapidshare membership!). How to produce a automation process to check on and demote an expired membership? It ought to be experience process focusing on the rear-finish (postgresql), but I am not necessarily sure. Any idea or solution?

Large thanks :)

A concept could be such as this:

  • User will pay for premium
  • Script card inserts an entry inside a database with premium rescheduling dates, with rescheduling date and user FK
  • A regular cron/at(based on OS) job searches the db for rescheduling dates using the date nowadays, and cancels the particular users' premium membership

I really hope it will help you :)

Why not check each time when user logs in?

Make use of a table schema like that one:

CREATE TABLE all_accounts (
    id INTEGER NOT NULL PRIMARY KEY,
    premium_expires DATE NOT NULL DEFAULT current_date,
    other_attrs,
    ...
);

Then produce a view that you simply use for queries:

CREATE VIEW accounts AS
SELECT
   account.*, current_date < account.premium_expires AS is_premium_membership
FROM
   account
WHERE 
   id = ?

Now a choose to accounts will yield an is_premium_membership attribute that is t when the premium membership applies. No requirement for background jobs.