T
T
toboe_kacuragi2018-11-26 13:44:02
CMS
toboe_kacuragi, 2018-11-26 13:44:02

How to asynchronously execute Lua code in Nginx location?

Hi all!
Problem in the following:
There is a normal location which processes incoming requests. It was necessary to add a counter to the mysql table, which takes into account some parameters from the request_uri for a given location.
As a result, the counter works fine, but there is one "But .." - when the tablet is blocked for writing (during the dump), Nginx returns an error 500. After increasing the timeout for the request, the page simply waits until the Lua script returns success or an error.
How can I make sure that the work of the counter does not affect the work of the rest of the location?
To work with MySQL, the library is used - lua-resty-mysql.
The script is "imported" into the location configuration via access_by_lua_file, because inside location there is a proxy_pass on the backend.
I'm new to lua-nginx, so I'll be glad for any help - up to links where and what to read.
Thank you!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Radmir, 2015-12-04
@spacyfox

I would also advise either Opencart or our Minicart CMS, if you don’t use it, just don’t display it, but as practice shows, any projects grow and sooner or later you will still need unnecessary functions, such as comparison of goods, the “postpone goods” function, card payments and much more.
Engines are made to suit the maximum number of people, so take a proven and most suitable for you without doping and preferably a boxed version, that is, a CMS that is only an online store and not WordPress.

A
Alexey Arkh, 2018-11-26
@AlekseyArh

Try to write
after the answer to the client.
Something like

ngx.say("привет")
ngx.eof() // тут клиент отключится
mysql:new() // всякая хрень дальше

L
Lynn "Coffee Man", 2018-11-26
@Lynn

I would do mirroring through mirror nginx.org/ru/docs/http/ngx_http_mirror_module.html
You can do anything in this location

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question