dqv84329
2017-01-05 14:13
浏览 79
已采纳

如何在CodeIgniter中记录Pusher PHP事件触发器失败?

So I have a problems working with Pusher on wamp server using CodeIgniter. Client side works fine, but PHP does not triger events. PHP does authenticate channels, but does not trigger events. If I use Pusher event creator clients get events.

Here is code:

function send_event($channel, $event, $message, $socket_id = NULL){
    $channel_array = array();
    array_push($channel_array, $channel);
    $data['message'] = $message;
    if(is_null($socket_id)){
        $response = $this->pusher->trigger($channel_array, $event, $data);
    }else{
        $response = $this->pusher->trigger($channel_array, $event, $data, $socket_id);
    }
    var_dump($response);        
}

var_dump return FALSE. I would want to understand the issue more but I am stuck on how to debug. From pusher PHP docs

class MyLogger {
  public function log( $msg ) {
    print_r( $msg . "
" );
  }
}

$pusher->set_logger( new MyLogger() );

But if I use this code I get CI errors. I tried to use myLogger in my Pusher library like this:

function __construct()
    {
        class MyLogger {
          public function log( $msg ) {
            print_r( $msg . "
" );
          }
        }

        $this->CI =& get_instance();
        $this->CI->load->library('tank_auth');

        require_once( 'Pusher.php' );

        $this->options['encrypted'] = true;
        $this->pusher = new Pusher(
            $this->key,
            $this->secret,
            $this->app_id,
            $this->options
        );
        $logger= new MyLogger;
        $this->pusher->set_logger( $logger );
    }

    function send_event($channel, $event, $message, $socket_id = NULL){
        $channel_array = array();
        array_push($channel_array, $channel);
        $data['message'] = $message;
        if(is_null($socket_id)){
            $response = $this->pusher->trigger($channel_array, $event, $data);
        }else{
            $response = $this->pusher->trigger($channel_array, $event, $data, $socket_id);
        }
        var_dump($response);        
    }

but got error:

Class declarations may not be nested
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题