Пример #1
0
<div class="container">

<?php 
require 'websocket_client.php';
// Handle request
if (isset($_POST['func'])) {
    switch ($_POST['func']) {
        case 'PHP':
            // Show Globals
            echo "<pre>Output from " . __FILE__ . ":</br>";
            echo print_r($GLOBALS, true) . "</pre>";
            break;
        case 'WS':
            // Aks the websocket server to show its globals
            $sp = websocket_open('127.0.0.1:8080/ws_request.php?param=php_test', $errstr);
            if (!$sp) {
                trigger_error($errstr);
            }
            // Send command and wait for an answer synchronously
            websocket_write($sp, json_encode(["php" => "websocket"]));
            echo "<Output via PHP websocket:</br>\n";
            echo websocket_read($sp, true);
            break;
    }
}
echo "</div>";
?>
</div>
</body>
</html>
 public function forceReload()
 {
     global $conf;
     if (constant('WEBSOCKET') != 1) {
         $sp = websocket_open('192.168.2.108:' . $conf['ws_port']);
         websocket_write($sp, "forcereload " . $conf['server_secure_hash']);
         if (websocket_read($sp, true) == "reload all") {
             websocket_write($sp, "disconnect ");
             return true;
         } else {
             websocket_write($sp, "disconnect ");
             return false;
         }
     } else {
         global $echo;
         $echo->refreshNotifications();
     }
 }