【问题标题】:How to make non blocking call in init_by_lua如何在 init_by_lua 中进行非阻塞调用
【发布时间】:2020-02-16 14:23:09
【问题描述】:
init_worker_by_lua_block {
  ....
  ngx.timer.every(10, MyFunction)
}

function MyFunction()
  local response = requests.get { url = url, headers = h }. 
  ...

MyFunction 通过“请求”发出 http 请求。这会每 10 秒阻塞一次传入请求。如何使这个非阻塞?

【问题讨论】:

    标签: nginx lua openresty


    【解决方案1】:

    假设您使用lua-resty-requests 库。

    在计时器上下文中,lua-resty-requests 使用非阻塞 cosocket API,所以它不应该阻塞。

    【讨论】:

    • 谢谢,这解决了问题。我正在使用 Lua 请求
    猜你喜欢
    • 1970-01-01
    • 2014-03-23
    • 2012-06-19
    • 1970-01-01
    • 2020-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-09
    相关资源
    最近更新 更多