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!

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

报告相同问题?

悬赏问题

  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥20 java在应用程序里获取不到扬声器设备