PHP在后台/服务器中运行

I would like to run PHP in Server like this for example i want to check customers birthdays...

$someones_birthday_today = mysql_query("SELECT * FROM users WHERE birthdate=".date('Y-m-d')." ");

if($someones_birthday_today){
    mysql_query("INSERT INTO birthdays (`user_id`, `birthdate`) VALUE ('$user_id', '$birthdate') ");
}

To query Select and Insert does not slow the process. But this is a Http Request From a Mobile App im developing. I dont want to Request everytime the user visit my app log view.

Every minute/day/month, it will check for birthdays today and insert to database this is for notifications. When a user logs in to his profile, php will then query the birthdays table if there are any.

Reasons: So that i want have to query select and insert everytime a users login to his profile. In this way, the page will load faster

Research: I did some research on cron job. It says that it should have an access to shell, in web host. But is there any other way?

Im using Mac Mavericks 10.9 Im using Laravel

Cron Jobs are not the right tool for this.

  • If you want to do this for the sole purpose of checking it on a user's profile, then you would just send this query when the user views his profile and be good with it. The query you posted is not particularly slow to run.

  • If indeed you want to determine the user's birthday on every page the user visits you might be better of loading the birthday when the user logs in and to remember the birthday by caching it in the user's session data or by using memcached.

  • If you want to show a list of birthdays or do any other sophisticated calculations then you could create a view to achieve pretty much the same thing you did with your select and subsequent insert:

    CREATE VIEW birthdays AS 
    SELECT user_id, birthdate FROM users WHERE birthdate=CURDATE();
    

    The difference is though that you only have to run the CREATE VIEW statement once (it is persistent). You can query the view like a table and it updates automatically when the date changes or new user records are inserted.

    Again - this is seriously overkill if you don't really need to query it a lot or have to do fancy stuff with it.