1
嗨我試圖從PHP發送事件到socketio服務器。我已經試過這兩個叉:從PHP向socket.io發送事件
https://github.com/rase-/socket.io-php-emitter
https://github.com/ashiina/socket.io-php-emitter
PHP代碼:
<?php
require_once('socketio/src/Emitter.php');
$emitter = new SocketIO\Emitter(array('port' => '6379', 'host' => '127.0.0.1'));
$emitter->broadcast->emit('testcall', 'data');
?>
的package.json:
{
"name": "Emitter",
"devDependencies": {
"express": "~4.13.4",
"socket.io": "~1.7.3",
"socket.io-redis": "~4.0.0"
}
}
節點服務器:
var app = require('express')(),
http = require('http').Server(app),
io = require('socket.io')(http),
redis = require('socket.io-redis');
http.listen(8081, function() {
console.log('\n==========================');
console.log('server listening on *:8081');
console.log('==========================\n');
});
io.adapter(redis({ host: '127.0.0.1', port: 6379 }));
io.on('connection', function(socket) {
socket.on('testcall', function() {
console.log('testcall');
});
});
我有redis-cli顯示器打開,我可以看到它發佈數據到redis,但我從來沒有看到日誌顯示。我可以從瀏覽器發出事件,但PHP的從不出現。
任何想法我做錯了什麼?
怎麼樣?面對相同,不知道如何接收事件客戶端 – Dennis