Loading...
This site is best viewed in a modern browser with JavaScript enabled.
Something went wrong while trying to load the full version of this site. Try hard-refreshing this page to fix the error.
请问哪位能给一个用openresty实现server sent event的例子
kytexzy
小弟初学openresty,对这玩意儿还有点陌生。
不知想试试用openresty实现sever sent event,不知哪位能给个简单的例子,谢啦!
--
with kind regards
kindy61
使用此处文档安装 ngx_openresty :
http://wiki.nginx.org/HttpLuaModule#Installation
安装后从
http://wiki.nginx.org/HttpLuaModule#Synopsis
选择一些 location 试试效果。
稍微熟悉了以后,可以使用这里 (
https://developer.mozilla.org/en-US/docs/Server-sent_events/Using_server-sent_events#Sending_events_from_the_server
)给出的例子,翻译成 lua 即可。
把相关代码写到 content_by_lua 或者 content_by_lua_file 内。
php 的 header 对应 lua 的
http://wiki.nginx.org/HttpLuaModule#ngx.header.HEADER
echo 对应 lua 的 ngx.print
ob_flush() 和 flush() 对应 lua 的 ngx.flush(true)
其他while循环之类参考 lua 文档
http://www.lua.org/manual/5.1/manual.html
另,content_by_lua 里写lua代码,记得转移 \ 和 ' , " 。
2012/12/6 Zheng Ping
<
kyt...@gmail.com
>
小弟初学openresty,对这玩意儿还有点陌生。
不知想试试用openresty实现sever sent event,不知哪位能给个简单的例子,谢啦!
--
with kind regards
--
- - - - - - - - - - - -
林青(Kindy Lin)