mysql - PHP CRON jobs vs. calling functions on a user login -
i'm hoping can advice.
i have accounting ledgers in php/mysql system, invoices hit ledger @ intervals (for example, let's once month). have late fees need applied after date. "posting" date of invoice, "this late" date in db already.
i'm wondering better method run script applies ledger item automatically (once month) - , enters late fee automatically (will once month, if needed). users of system, these dates different - , said, stored in db. options see are:
have cron job runs once day (i.e. 12:00am each day) - , goes through every item, doing work if date conditions met.
i think method, because takes care of @ once, @ same time every day.
i worried method because: (1) if server down when cron job scheduled, cpanel skip day now? , (2) if have 100k or 100million entries sift through, unbearable load on server whenever ran?
call script "do work" if date conditions met, only when related user logs in.
the reason why don't method much, because gets increasingly complex tell how many invoices apply, , how many late fees apply. further, have "administrator" user can see - user may have not date ledger info if tenant hasn't logged in enough...
the reasn method, because less load on server...
perhaps i'm on thinking things. not sure... advice appreciated. thanks.
i think best bet use cron tab, benefits mention. add though if use transaction safe table, such innodb, , log completion of cron tab, if table crashes during crontab changes reverted , can check log see dates had crashes can manually make changes. in fact, if log crontab task's completion in table, can use log (grabbing how many days ago script run last) automatically handle missed days.
as far server load, won't have of problem updating many records @ once. thing structured query, should updating (or inserting) based on records have date matches selected parameters. shouldn't need loop through every record in db.
Comments
Post a Comment