webソケット通信をするjsファイルをphpから制御しようとしています。
main.js
1$(function(){ 2 var ws = null; 3 var open = false; 4 5 var fun_WebSocket = function(){ 6 ws = new WebSocket('wss://hogehogehoge'); 7 ws.onmessage = function(e){ 8 }; 9 ws.onclose = function(){ 10 }; 11 ws.onopen = function(){ 12 open = true; 13 }; 14 ws.onerror = function(event) { 15 }; 16 } 17 18 function repeat_submit() { 19 const obj = { 20 module: 'hogehoge', 21 type: 'channels', 22 datetime: new Date().toISOString(), 23 payload: {channels: [{channel: 0, type: 'I', value: 1}]} 24 }; 25 var repeat = setTimeout(repeat_submit, 1000); 26 if(open) { 27 ws.send(JSON.stringify(obj)); 28 clearTimeout(repeat); 29 } 30 } 31 32 fun_WebSocket(); 33 repeat_submit(); 34 35}); 36
このファイルを、下記のようにhtmlファイルから読み込んでいます。
<!DOCTYPE html> <html lang="ja"> <head> <meta charset="utf-8"> <title>title</title> </head> <body> <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script> <script type="text/javascript" src="./main.js"></script> </body> </html>
みたいな形で読み込んでいます。
phpから上記のjsを実行したいのですが、
<?php $options = array( 'http'=>array( 'method'=>'GET', 'header'=>"User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)\r\n". "Accept-language: ja\r\n" ) ); $context = stream_context_create( $options ); $contents = file_get_contents( 'http://hogehoge.com', FALSE, $context ); echo $contents; ?>
としてもhtmlファイルが返ってくるだけです。
どのようにすればブラウザと同様にjsを実行できるのでしょうか。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。