I'm very new to WebSockets and have been playing with Ratchet and gotten a simple chat room to work on my AWS EC2 instance. Now I'm trying to use another service which can run a custom PHP script (hosted on their servers) to open a websocket connection on my server and send a message.
I got the EC2 URL working, and when I run it in my browser (including on my phone, which isn't on the same network as my computer) it works. I'm simply passing a testing API key and the value in the URL for now (grabbed with PHP GET), like so:
This works, but only because the ws-trigger.php
page loads the following JavaScript and runs it from the browser:
<script type="text/javascript">
var conn = new WebSocket('ws://22.222.22.222:8080');
conn.onopen = function(e) {
console.log("Connection established!");
conn.send(<?php echo $_GET['name']; ?>);
};
</script>
What is the easiest way for me to run this "connect to the websocket" and "send a message over the socket" via PHP? If I have to use a library I'd prefer use Ratchet since I already am, but I feel like I must be missing something because this cannot be a unique problem.
I have tried searching StackOverflow already, but have had issues with the few answers I'd already found (like phpwebsocket was giving me troubles before I moved to Ratchet, and this one isn't a PHP WS client at all)