Php read socket stream/push data from local app

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • neal77
    New Member
    • May 2015
    • 1

    Php read socket stream/push data from local app

    I connect to an application that should give me a push/stream data.

    With the following code I have a positive answer from the app (outcome=OK|ite m=THEITEM) but I can't figure out how to get the var "last_value " and its updates. The loop is commented out, I have no echo with it (infinite loop)
    Code:
    $port = ('5333');  
    $address = ('127.0.0.1');   
    $fp = stream_socket_client("tcp://$address:$port", $errno, $errstr, 1);  
    if (!$fp) {  
            echo "$errstr ($errno)<br />\n";  
    } else {    
            $in = "function=subscribe|item=THEITEM|schema=last_value";  
            fwrite($fp, $in."\n");  
            //while (!feof($fp)) {  
                    echo fgets($fp, 1024);  
            //}  
            fclose($fp);  
    }
    This returns outcome=OK|item =THEITEM. The updates (push/stream data) should be like THEITEM|last_va lue.

    (mac osx 10.10, mamp)
Working...