3

I am conecting to a feed using the STOMP protocol in PHP

Because there are not many messages coming from the feed I believe my script thinks I have lost connection and the below error pops out:-

Uncaught exception 'StompException' with message 'Unexpected EOF while reading from socket'

If I can send a heart beat I believe the script will keep running - ie know I'm still there

The code is below. My problem is that I am getting errors. See NEW EDIT below

             $channel="VSTP_ALL";
             $con=new Stomp($server,$user,$password,array('heart-beat'=>'0,20000'));
              if (!$con) {
                die('connection failed: ' .stomp_connect_error());
                }
             $con->subscribe("/topic/".$channel);

              if ($con->hasFrame()){
              $msg=$con->readFrame();
              foreach (json_decode($msg->body) as $event) {
              var_dump($event);
              }
              $con->ack($msg);  
              }
              die ('connection lost:'.time());

             ?>

EDIT

Have edited above to move/change syntax of array('heart-beat','0,20000') to array('heart-beat'=>'0,20000')

However I now get errors as follows in the foreach line:-

Notice: Trying to get property of non-object in

Warning: Invalid argument supplied for foreach()

and then in the ack($msg) line

Warning: Stomp::ack(): Expects parameter 2 to be a string or a StompFrame object. in

user2635961
  • 379
  • 3
  • 19
  • I have to use a heartbeat when using websockets. My crappy home cable router will kill connections that are idle too long (SSH too). I send a short message every 30 seconds from my websocket applications to the server (that is received and then ignored) and set my ServerAliveInterval to 60 for SSH. – Skrrp Aug 24 '15 at 17:02
  • Is php-stomp supports heart-beats? In php-stomp sources no words "heart" "beat" "keep" "alive". – Hayate Dec 12 '15 at 03:29

0 Answers0