lua清除cdn程序
来源:互联网 发布:7u分享网络赚一元 编辑:程序博客网 时间:2024/06/05 19:33
#!/bin/luarequire "socket"local ID= '330B'local TOK= '0585c133-dfd5-4be0-816a-erettyty232rtyuasad'local URL_LIST_FILE= './cdn.txt'local GET_CONTENT= [[GET /v2/reporting/customers/3A0B/media/8/cachestats?begindate=2010-01-01&enddate=2013-12-01 HTTP/1.1Accept-Encoding: identityAccept: application/jsonHost: api.edgecast.comConnection: closeAuthorization: TOK:0585c133-dfd5-4be0-erettyty232rtyuasadUser-Agent: Python-urllib/2.7]]local POST_CONTENT= [[PUT /v2/mcc/customers/3A0B/edge/purge HTTP/1.1Accept-Encoding: identityContent-Length: $$$Connection: closeAccept: application/jsonUser-Agent: Python-urllib/2.7Host: api.edgecast.comContent-Type: application/jsonAuthorization: TOK:0585c133-dfd5-4be0-816a-a19db2319ea9{"MediaPath": "%s","MediaType": 8}]]local host= 'api.edgecast.com'local threads = {}function receive(connection) connection:settimeout(0) local s, status, partial = connection:receive('*a') if status == "timeout" then coroutine.yield(connection) end return s or partial, statusendfunction request(data) local c = assert(socket.connect(host, 80)) local count = 0 --print(data) assert(c:send(data)) while true do local s, status, partial = receive(c) count = count + #(s or partial) if status == "closed" then break end if not s then print(status, partial) else print(s) end end c:close()endfunction info() local co = coroutine.create(function () request(GET_CONTENT) end) table.insert(threads, co)endfunction clear() local cdn_file = io.open(URL_LIST_FILE,"r") local content local count local continue for line in cdn_file:lines() do line= line:gsub("^%s+", ""):gsub("%s+$", "") if(not string.len(line)) then continue= false else continue= true end if continue== true then content= string.format(POST_CONTENT, line) _, pos= string.find(content, "\n\n") count= string.len(string.sub(content, pos+1, -1)) --print(string.sub(content, pos+1, -1)) content= content:gsub("($$$)", count) print(content) local co = coroutine.create(function () request(content) end) table.insert(threads, co) end endendfunction dispatch() local i = 1 local connections = {} while true do if threads[i] == nil then if threads[1] == nil then break end i = 1 connections = {} end local status, res = coroutine.resume(threads[i]) if not res then table.remove(threads, i) else i = i + 1 connections[#connections + 1] = res if #connections == #threads then socket.select(connections) end end endendif #arg <1 then print('parameter error.')else if arg[1]== 'info' then info() dispatch() elseif arg[1]== 'clear' then clear() dispatch() else print('Usage: lua cdn.lua info, lua cdnlua clear') endend
0 0
- lua清除cdn程序
- redis+lua+nginx打造CDN云加速
- Lua - Lua协同程序
- 清除系统垃圾程序
- 清除系统垃圾程序
- 线程清除处理程序
- Android 清除程序缓存
- 微信小程序清除浮动
- CDN
- cdn
- CDN
- CDN
- CDN
- CDN
- CDN
- CDN
- cdn
- CDN
- Fibonacci数列的幂和
- struts2结合过滤器和cookie实现自动登录
- JS 数字金额用逗号隔开(数字格式化及将数字金额变成中文大写金额
- 第14届浙江大学程序设计竞赛 D. Ranking System(ZOJ 3770)
- ASP.NET初探--如何运行下载下来的项目
- lua清除cdn程序
- matlab:寻找峰值(波峰,波谷)
- 并查集
- hdu 简单题
- Linux内核模块-实例2(二)
- iPhone/iPad高级应用与手游开发学习笔记:AVAudioPlayer学习(音频播放demo)
- 输入一个小数,按不同格式输出
- 关于serveletContext.getRealPath()方法
- 第14届浙江大学程序设计竞赛 I. ?(>_o)! (ZOJ 3775)