doujian1050 2015-03-02 02:35
浏览 36

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

  • 写回答

1条回答 默认 最新

  • dongshi2588 2015-03-02 03:16
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘