Foro de elhacker.net

Programación => PHP => Mensaje iniciado por: geshiro en 22 Abril 2017, 03:48 am



Título: websocket ratchet
Publicado por: geshiro en 22 Abril 2017, 03:48 am
lo que queiero hacer es como mandar los mensajes a la base de datos para poder mostrarlos en la vista usando ratchet websocket . mis websocket ya los genera pero desde otro php para generarlos por medio de un boton como prueba pero como pudiera hacerlos de manera dinamica para detectar el evento y mostrarlos ?

Código
  1. public function pusher(){
  2.     $entryData = array(
  3.         'category' => $this->input->post('category'),
  4.         'title'    => $this->input->post('title'),
  5.         'article'  => $this->input->post('article'),
  6.         'timestamp'     => time()
  7.     );
  8.  
  9.    //$this->notification->addNotification($entryData);
  10.  
  11.    // This is our new stuff
  12.  
  13.    $context = new ZMQContext();
  14.    $socket = $context->getSocket(ZMQ::SOCKET_PUSH, 'my pusher');
  15.    $socket->connect("tcp://localhost:5555");
  16.  
  17.    $socket->send(json_encode($entryData));
  18.    print_r($entryData);
  19.  
  20. }

Código
  1. var sock = new ab.Session('ws://192.168.0.4:8080',
  2.        function() {
  3.            sock.subscribe('kittensCategory', function(topic, data) {
  4.                $badge.show();
  5.                $badge.text(parseInt($badge.text()) + 1);
  6.  
  7.                $list.find(".item").eq(13).nextAll(".item").remove();
  8.                var item = '<li class="item text-warning"><a href="#"><span class="text-warning">' +
  9.                    '<i class="fa fa-exclamation-triangle fa-fw"></i>'+data.title+' is low'+'</span>' +
  10.                    '<span class="pull-right text-muted small" data-time="">'+data.timestamp+'</span></a></li>' +
  11.                    '<li class="item divider"></li>';
  12.                $list.prepend(item);
  13.                $('.dropdown.open .dropdown-toggle').dropdown('toggle');
  14.            });
  15.        },
  16.        function() {
  17.            console.warn('WebSocket connection closed');
  18.        }, {
  19.            'skipSubprotocolCheck': true
  20.        }
  21.    );
  22.