https://github.com/linzap/longpolling_room
long polling chatroom sample
https://github.com/linzap/longpolling_room
Last synced: 11 months ago
JSON representation
long polling chatroom sample
- Host: GitHub
- URL: https://github.com/linzap/longpolling_room
- Owner: LinZap
- Created: 2014-04-30T19:34:16.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2014-11-15T08:59:38.000Z (over 11 years ago)
- Last Synced: 2025-04-23T18:53:31.660Z (about 1 year ago)
- Language: PHP
- Homepage: http://zap.comze.com/longpolling_room/
- Size: 214 KB
- Stars: 3
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
longpolling_room
================
這是一個實作 Long polling 機制的 web 程式
沒有多餘不相干的功能,純粹的 comet programming 基本範例
Long polling 的介紹可參考這篇[詳細介紹](http://josephj.com/entry.php?id=358)
## 程式介紹
1. index.php 為主程式進入點
2. allmsg.php 為第一次程式進入,抓取所有訊息
3. connect.php 資料庫連接,統一函式
4. logout.php 清除 SESSION 達到登出的效果
5. longpolling.php 程式反覆存取這隻程式,已取得最新資料,反映到畫面
6. sendmsg.php 使用者藉這隻程式,將訊息傳送出去,並保存於資料庫
7. signin.php 使用者第一次需要先登入(只要求輸入姓名)
## 資料庫 架構介紹
本系統的資料庫架構十分簡易,資料表與欄位如下
### Schema 介紹
1. user (uid,name) 儲存使用者基本資料
2. msg (id,content,send,time) 儲存使用者傳送的訊息
3. notify (name,isnews,time) 記錄使用者抓取資料的最後時間,藉由存取該資料表,判斷是否有新資料,藉此撈取該訊息
### 建立資料庫 SQL 語法
CREATE TABLE msg (
id int(11) NOT NULL auto_increment,
content varchar(500) default NULL,
send varchar(50) NOT NULL,
time datetime NOT NULL,
PRIMARY KEY (id)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;
* * *
CREATE TABLE notify (
name varchar(50) NOT NULL,
isnews tinyint(4) NOT NULL,
time datetime NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
* * *
CREATE TABLE user (
uid int(11) NOT NULL auto_increment,
name varchar(50) NOT NULL,
PRIMARY KEY (uid)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;
## 架構 與 Demo
1. 本程式全部由 php 撰寫
2. 資料庫使用 MySQL 5.4
3. 後端Server位於 ueuo.com
4. Live Demo : http://zap.comze.com/longpolling_room/
## License
Copyright 2014 LinZap
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.