【问题标题】:Emitting events to socket.io from PHP从 PHP 向 socket.io 发送事件
【发布时间】:2017-04-20 17:19:55
【问题描述】:

您好,我正在尝试将事件从 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' );

?>

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 的事件永远不会出现。

任何想法我做错了什么?

【问题讨论】:

    标签: socket.io socket.io-redis


    【解决方案1】:

    它有效我只是愚蠢。来自 PHP 的事件正在发送,但发送到客户端而不是服务器。貌似我忘了它是怎么工作的哈。

    【讨论】:

    • 怎么样?面对相同,不知道如何在客户端接收事件
    猜你喜欢
    • 2014-01-30
    • 2018-01-29
    • 2016-10-14
    • 1970-01-01
    • 2014-03-16
    • 2021-08-20
    • 2013-02-13
    • 1970-01-01
    • 2017-05-20
    相关资源
    最近更新 更多