Astro,
This is actually pretty straight forward and can be accomplished a couple of different ways. We designed the Thruway Client to mimic the AutobahnJS client, so most of the simple examples will translate directly.
I'm assuming that you want to publish from a website (not a long running php script).
In your PHP website, you'll want to do something like this:
$connection = new \Thruway\Connection(
[
"realm" => 'com.example.astro',
"url" => 'ws://demo.thruway.ws:9090', //You can use this demo server or replace it with your router's IP
]
);
$connection->on('open', function (\Thruway\ClientSession $session) use ($connection) {
//publish an event
$session->publish('com.example.hello', ['Hello, world from PHP!!!'], [], ["acknowledge" => true])->then(
function () use ($connection) {
$connection->close(); //You must close the connection or this will hang
echo "Publish Acknowledged!\n";
},
function ($error) {
// publish failed
echo "Publish Error {$error}\n";
}
);
});
$connection->open();
And the javascript client (using AutobahnJS) will look like this:
var connection = new autobahn.Connection({
url: 'ws://demo.thruway.ws:9090', //You can use this demo server or replace it with your router's IP
realm: 'com.example.astro'
});
connection.onopen = function (session) {
//subscribe to a topic
function onevent(args) {
console.log("Someone published this to 'com.example.hello': ", args);
}
session.subscribe('com.example.hello', onevent).then(
function (subscription) {
console.log("subscription info", subscription);
},
function (error) {
console.log("subscription error", error);
}
);
};
connection.open();
I've also created a plunker for the javascript side and a runnable for the PHP side.