从 mysql 中的触发器调用 url [英] Calling an url from a trigger in mysql

查看:40
本文介绍了从 mysql 中的触发器调用 url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这是极不推荐的,

I know it's highly unrecommended,

我知道这是性能、速度等方面的问题,但这是为了集成,他们只通过 mysql 进行更新(我知道这样做也很疯狂,但我无法改变他们所做的事情,而且他们的销售量很大,所以他们不想改变任何东西).

I know that it's an issue with performance, speed, etc, but it's for an integration, and they only are doing their updates via mysql (I know it's crazy to do that too but I can't change what they do, and they are making a ton of sales so they don't want to change anything).

我只需要发布到一个 URL(它可以像 http://www.google 一样简单.com?id=skuid)

I only need to post to a URL (it can be as simple as http://www.google.com?id=skuid)

我读过这个博客和堆栈,但它们已经超过 2 年了,想知道是否有使用 udf 的替代方法:

I read this blogs and stacks, but they are 2+ years old, would like to know if there are alternatives to using an udf:

http://open-bi.blogspot.pe/2012/11/call-restful-web-services-from-mysql.html

http://www.mooreds.com/wordpress/archives/1497

使用mysql触发器调用php文件

非常感谢您所做的一切!!

Thanks a lot for everything!!

推荐答案

要触发外部操作,您必须使用 UDF - 这是 mysql 将某些事情告诉外部"的唯一方法世界".唯一的选择是外部代理不断轮询数据库 - 这是一个较差的解决方案.

To trigger an external action, you have to use a UDF - it's the only way for mysql to tell something to the "outside world". The only alternative is an external agent polling the DB constantly - which is an inferior solution.

关于UDF的选择,

  • 为了尽量减少 DB 上的负载,它可能应该快速完成(注意 UDF 同步运行).
  • 因此,除非安装规模足够小,否则它只会将事件通知给外部代理.这也最大限度地减少了 DB 端的错误处理.
    • 否则,如果您(还)不关心,您可以例如只需生成 curl 即可.

    想到的方法:

    • 生成一个小程序 - 例如touch 代理监视的某个文件.有一个现有的 sys_exec 使用 system()(考虑到所有应有的考虑).
    • IPC(信号是最简单的;对于其他信号,您可以传递附加信息,但需要更多设置)
    • spawn a small program - e.g. touch some file which the agent watches. There's an existing sys_exec that uses system() (with all due considerations).
    • IPC (signal is the simplest; with others, you can pass additional information but it requires more setup)

    作为 sys_exec 的来源 显示,编写 UDF 并没有那么难,因此您并不仅限于已经可用的内容(这可以解释为什么 lib_mysqludf_sys 如此有限:如果您需要更好的东西,那么很容易编写特定于任务的函数).当前文档位于 26.4.2 添加新的用户定义函数- MySQL 5.7 参考手册.

    As the sys_exec's source shows, it's not so hard to write a UDF, so you aren't really limited to what's already available (this may explain why lib_mysqludf_sys is so limited: if you need something better, it's sufficiently easy to write a task-specific function). The current docs are at 26.4.2 Adding a New User-Defined Function - MySQL 5.7 Reference Manual.

    这篇关于从 mysql 中的触发器调用 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆