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

查看:652
本文介绍了从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文件

非常感谢!

推荐答案

要触发外部动作,您必须使用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,

  • 为了最大程度地减少数据库上的负载,它应该可以快速完成(注意UDF是同步运行的).
  • 因此,除非安装的规模足够小,否则它只会将事件通知外部代理.这也使DB端的错误处理最小化.
    • 否则,如果您不关心,可以例如只需生成curl就可以了.
    • to minimize load on the DB, it should probably be something that finishes quickly (note that UDFs run synchronously).
    • So, unless the installation is sufficiently small-scale, it's going to merely notify an external agent of the event. This also minimizes error handling at the DB side.
      • Otherwise, if you don't (yet) care, you can e.g. just spawn curl for all it's worth.

      想到的方式:

      • 产生一个小程序-例如touch代理监视的某些文件.有一个使用system() sys_exec (出于所有考虑).
      • 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天全站免登陆