lua_code_cache on or off

329 views
Skip to first unread message

jijilu

unread,
Jul 9, 2013, 6:07:11 AM7/9/13
to open...@googlegroups.com
when I turn lua_code_cache on ,

local uri = "url";
local res = ngx.location.capture(uri);
if res.status == 200 then
-- ngx.print(res.body);
local tbody = res.body;
-- search for substatement having the tag "RequestResponse"
local idx1 = string.find(tbody, "<RequestResponse");
local idx2 = string.find(tbody, "</RequestResponse>");
local prdata = string.sub(tbody, idx1, idx2+17);
local pr_xml = xml.eval(prdata);

local pr_xml = xml.eval(prdata); this line will be wrong to echo server 500 error.

but turn lua_code_cache off, the same error is gone.


@jijilu

Yichun Zhang (agentzh)

unread,
Jul 9, 2013, 3:05:30 PM7/9/13
to openresty
Hello!

On Tue, Jul 9, 2013 at 3:07 AM, jijilu wrote:
>
> local pr_xml = xml.eval(prdata); this line will be wrong to echo server 500 error.
>

I didn't see how you initialize the "xml" Lua variable here.

> but turn lua_code_cache off, the same error is gone.
>

That usually means you didn't "require" the Lua module in the right
way. The correct syntax for loading a Lua module is

local foo = require "foo"

rather than just

require "foo"

BTW, English posts are better for the openresty-en mailing list:
https://groups.google.com/group/openresty-en

Best regards,
-agentzh

jij...@189.cn

unread,
Jul 23, 2013, 3:01:27 AM7/23/13
to open...@googlegroups.com
hi,agentzh

sorry for my delay.

After turn lua_code_cache on,

local xml = require("LuaXml");
local uri = "";


local res = ngx.location.capture(uri);
if res.status == 200 then

local pr_xml = xml.eval(prdata);
local xscene = pr_xml:find("DomesticFlightRoute");
local rcs = tonumber(xscene[1][1]);

rcs will be nil when system load in case of high concurrent rate.

Yichun Zhang (agentzh)

unread,
Jul 23, 2013, 3:14:09 PM7/23/13
to openresty
Hello!

On Tue, Jul 23, 2013 at 12:01 AM, jijilu wrote:
>
> After turn lua_code_cache on,
>
> local xml = require("LuaXml");
> local uri = "";
> local res = ngx.location.capture(uri);
> if res.status == 200 then
> local pr_xml = xml.eval(prdata);
> local xscene = pr_xml:find("DomesticFlightRoute");
> local rcs = tonumber(xscene[1][1]);
>
> rcs will be nil when system load in case of high concurrent rate.
>

By looking at the source code of LuaXML 1.7.4 (as seen here:
http://viremo.eludi.net/LuaXML/#download ), one obvious mistake in the
xml.eval function's implementation (i.e., the Xml_eval C function) is
use of lua_getglobal to access the "xml" global variable. Descent Lua
modules should never assume that such a global variable exists (nor
polluting the global environment for any reasons). You should ask the
author of LuaXML to fix this issue on his side or you can look for a
better Lua library that can do XML.

BTW, please join the mailing list before posting. Otherwise, your
posts always require manual moderation.

Best regards,
-agentzh
Reply all
Reply to author
Forward
0 new messages