laruence/yar

有支持lua的计划么 服务端

Closed this issue · 6 comments

配合 openrestry 玩,很合适啊, 它专做api

我没有, 你做一个开源呗 嘿嘿 :)

ngx_lua 服务端代码

location /test
{
content_by_lua '
ngx.req.read_body()
local body = ngx.req.get_body_data()
local header = string.sub(body,1,82)
local package = string.sub(body,83,90)
local _body = string.sub(body,91)
local cjson = require "cjson"
local result = cjson.decode(_body)
local id = result.i
local respone = {i=id,s=200,r="hehe",o="hehe",e="error"}
local result = cjson.encode(respone)
local sendout = table.concat({header,package,result})
ngx.log(ngx.ERR,sendout)
ngx.say(sendout)
return
';
}

client 代码

$client = new Yar_Client("http://localhost/test");
$client->SetOpt(YAR_OPT_PACKAGER, "json");
$result = $client->api("quqiufeng@gmail.com");
print_r($result);

报错信息

Fatal error: Uncaught exception 'Yar_Client_Exception' with message 'error' in /var/www/caijia/test.php:5 Stack trace: #0 /var/www/caijia/test.php(5): Yar_Client->__call('api', Array) #1 /var/www/caijia/test.php(5): Yar_Client->api('quqiufeng@gmail...') #2 {main} thrown in /var/www/caijia/test.php on line 5

求帮助!!!

你没有错误就不要返回e啊.... 你都返回e(exception)了, 客户端当然如实的抛出异常了 :<

哦 哦 搞定了

http://quqiufeng.blog.163.com/blog/static/24255301420156273143583/

另外 r 跟 o 有什么区别
s != "" 会报错

r是return, o是output, 一般用不到o(就是直接输出)