Implementing Heart Beat in PHP with STOMP

I am connecting to a channel using the STOMP protocol in PHP

Since there are not many posts from the feed, I believe my script thinks that I have lost the connection and the below error appears: -

Throw "StompException" with "Unexpected EOF while reading from socket"

If I can send the heart rate I trust the script will keep running i.e. 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

Edited above to move / change array syntax ('heart-beat', '0.20000') to array ('heart-beat' => '0.20000')

However, now I am getting the following errors on the foreach line: -

Note. Trying to get a property of a non-object in

Warning: Invalid argument provided by foreach ()

and then on the line ack ($ msg)

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

+3


source to share





All Articles