This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
socket.on('send', function(msg) { | |
// 廣播資訊給在socket.room的人,除了發送者自己 | |
socket.broadcast.to(socket.room).emit('updatechat', msg); | |
// 傳送更新資訊給自己 | |
socket.emit('updatechat', msg); | |
socket.to(socket.room).emit('updatechat', msg); | |
// 傳送資訊給所有socket | |
io.sockets.emit('updatechat', msg); | |
// 傳送資訊給在socket.room的連線 | |
io.sockets.in(socket.room).emit('updatechat', msg); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 新增當地時區的時間物件 | |
function DateTimezone(offset) { | |
// 建立現在時間的物件 | |
d = new Date(); | |
// 取得 UTC time | |
utc = d.getTime() + (d.getTimezoneOffset() * 60000); | |
// 新增不同時區的日期資料 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// 連線Memcache | |
$meminstance = new Memcache(); | |
$meminstance->pconnect('localhost', 11211); | |
// 存放資料到Memcache | |
$cache_key = 'hello_memcache'; | |
$cache_data = 'cache_info'; | |
$meminstance->set($cache_key, $cache_data, 0, 600); | |
// 讀取Memcached存放的資料 | |
$res = $meminstance->get($cache_key); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 引用MySQL函式庫 | |
var mysql = require('mysql'); | |
// 資料庫設定 | |
var db_config = { | |
user: '資料庫帳號', | |
password: '資料庫密碼', | |
host: '主機位置', | |
port: '資料庫port' | |
database: '資料庫名稱' | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 關閉資料庫連線 | |
connection.end(function(err) { | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 引用MySQL函式庫 | |
var mysql = require('mysql'); | |
// 建立資料庫連線池 | |
var pool = mysql.createPool({ | |
user: '資料庫帳號', | |
password: '資料庫密碼', | |
host: '主機位置', | |
port: '資料庫port' | |
database: '資料庫名稱', | |
// 無可用連線時是否等待pool連線釋放(預設為true) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php namespace Entities; | |
// model/Entities/Pokemon.php | |
class Pokemon extends \Eloquent { | |
/** | |
* The database table used by the model. | |
* | |
* @var string | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php namespace Repositories\Pokemon; | |
// model/Repositories/Pokemon/PokemonInterface.php | |
/** | |
* A simple interface to set the methods in our Pokemon repository, nothing much happening here | |
* 簡單的介面去設定我們的 Pokemon 資源庫 | |
*/ | |
interface PokemonInterface | |
{ | |
public function getPokemonById($pokemonId); |