开发者

Need to check if users are logged in before an appointed time

I have a PHP-开发者_开发技巧based appointment scheduling application which requires certain users to be logged in 15 minutes before an appointed time.

If the users forget to log in, an email reminder has to be sent to them with the help of a cron job.

I've included a flag in the database that checks if the user has logged in. This flag is turned on when at login time, and turned off when the user manually signs out.

What if the user's session expires? What should I implement in the cron job to take this factor into account?


You'd have to implement your own custom session handler (probably using a database). PHP's default handler doesn't expose any kind of monitoring/event notification that would let you detect an expired/garbage collected session.

You COULD use an external process to manually slog through the session files, but that's somewhat racy: the session could be expired and the PHP garbage collector gets to it before your monitoring script does.

Given that you're storing a "logged in" flag in the database, a cron job to check for not-yet-logged-in users is the easiest way to go, however the scheduling of the job could be somewhat ugly. If your appointed times are essentially random, you'd either have to the job running every minute (the shortest interval cron supports directly), or schedule an individual job for each event. For less coarse scheduling points, you could probably use cron's wildcard/fixed point syntax, eg. "*/5,10,15,... * * * *"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜