douzhang5199 2018-04-12 18:34
浏览 61
已采纳

新插入后立即从mysql获取更新

I have a webshop, user order's will be saved on mysql and it will be process later in batch by "processor.php", it will be processed later because the requirement to send this order to other server is using a chat application

processor.php is a jabber bot, php bot that will be running 24/7 and it will check at db every 5 minutes and process the orders (send it to another bots, and update the orders based on the other bots reply)

I'am wondering if there is a way so processor.php can have a notification like "hey there is a new order, process it" from mysql every time a user submit a new order, something like a real time

  • 写回答

1条回答 默认 最新

  • douji7399 2018-04-12 19:00
    关注

    The best you can do is edit the file that INSERTS the data in the first place.

    You can use $query->insert_id; or a myqsli equivalent if you need the ID of the new order

    You can then pass this ID to the processor. Believe me, relying on crons can become a nightmare and with payments and orders I highly recommend avoiding a cron solution.

    That said, if your processor only changes things in the DB itself and nothing else you can use internal MySQL triggers!

    https://www.siteground.com/kb/mysql-triggers-use/

    But if your processor does non-DB work you will have to either:

    Use your cron

    Set up the order insert to then also trigger the processor on it's own without using a cron.

    Set up a function that looks to see if order is ready for processing on a page a user visits, so that their order can begin processing without any delay.

    You can use AJAX or even PHP to call processor.php. you can even pass it a specific ID. Essentially any basic method like file get contents, $.get(), or any other programming function (in any language) will let you call processor.php and have that file run on your web server. You can do this from any language that supports requesting a file from the same or different server (so most).

    I highly recommend making sure you set up proper permissions and even a basic API so only YOUR server(s) and service(s) can trigger the processor!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么