您好我正在尝试将事件从 PHP 发送到 socketio 服务器。我试过这两种叉子:
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' );
?>
包.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 的永远不会出现。
任何想法我做错了什么?