Swift...18 서버 사이드 Swift
Server-side Swift를 만들어 보세요.
환경 변수만 얻으면 CGI를 할 수 있다.
NSProcessInfo.processInfo().environment
뿐이다.간단해 보여요.import Foundation
class CGI {
var p = [String:String]()
init() {
// プロセスの環境変数を取得
let ENV = NSProcessInfo.processInfo().environment
// 環境変数からQUERY_STRINGを取得
if let params = ENV["QUERY_STRING"] {
params.componentsSeparatedByString("&").forEach {
let kv = $0.componentsSeparatedByString("=")
p[kv[0]] = kv[1]
}
}
}
func param(key:String) -> String {
if let ret = p[key] {
return ret
} else {
return ""
}
}
}
let q = CGI()
print("Content-type: text/html; charset=utf-8\n")
print("<!DOCTYPE html>")
print("<html lang=\"ja\">")
print("<head>")
print("<meta charset=\"UTF-8\">")
print("<meta name=\"viewport\" content=\"width=device-width\">")
print("<title>Hello Swift</title>")
print("</head>")
print("<body>")
print("<h4>Request Parameter</h4>")
print("<p>name : \(q.param("name"))</p>")
print("<p>age : \(q.param("age"))</p>")
print("</body>")
print("</html>")
printenv.cgi
아파치 벤치를 찾아보세요.
# ab -n 1000 -c 10 "http://localhost/cgi-bin/printenv.cgi?name=Qiita&age=123"
Server Software: Apache/2.4.16
Server Hostname: localhost
Server Port: 80
Document Path: /cgi-bin/printenv.cgi?name=Qiita&age=123
Document Length: 238 bytes
Concurrency Level: 10
Time taken for tests: 5.110 seconds
Complete requests: 1000
Failed requests: 0
Total transferred: 392009 bytes
HTML transferred: 238000 bytes
Requests per second: 195.68 [#/sec] (mean)
Time per request: 51.104 [ms] (mean)
Time per request: 5.110 [ms] (mean, across all concurrent requests)
Transfer rate: 74.91 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.4 0 9
Processing: 15 50 12.9 49 145
Waiting: 14 50 12.6 48 144
Total: 15 51 12.9 49 145
Server Software: Apache/2.4.16
Server Hostname: localhost
Server Port: 80
Document Path: /cgi-bin/env.cgi?name=Qiita&age=123
Document Length: 736 bytes
Concurrency Level: 10
Time taken for tests: 3.631 seconds
Complete requests: 1000
Failed requests: 0
Total transferred: 877227 bytes
HTML transferred: 736000 bytes
Requests per second: 275.43 [#/sec] (mean)
Time per request: 36.307 [ms] (mean)
Time per request: 3.631 [ms] (mean, across all concurrent requests)
Transfer rate: 235.95 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.5 0 6
Processing: 12 36 18.9 33 341
Waiting: 11 33 11.3 32 340
Total: 12 36 18.9 33 342
총결산
Reference
이 문제에 관하여(Swift...18 서버 사이드 Swift), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/qoAop/items/a5e88b847e831aeb7c98텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)