marceloandrader

marceloandrader

Using phoenix channels outside an elixir phoenix webapp

Hi there,

I have a PHP app (it’s big can’t migrate it to elixir) so for pseudo real time communications, I’m using a request that uses Server Sent Events that start a redis subscribe to specific channels and on each message I sent to the client, so I can send notifications/progress/etc to the client from the server. The issue is that this requests are long lived, and they are using too much resources in the server.

I’m trying to move to websockets instead of SSE, but in php it looks super complex. I was wondering if I can use channels outside elixir, looks like the way to send messages is simple enough I can write a client in php, but tried to add the js socket client to my app and it didn’t work. It’s trying to open the websocket connection to the same host the website is running instead of the webserver where phoenix app is running, not sure how to specify the right host in the js client.

And what is the best way to secure this scenario?

Thanks in advance

Most Liked

Hermanverschooten

Hermanverschooten

If what you want to do is, connect to the channels from the JS side. You only need to include the phoenix javascript and setup the connections as it is done in a normal phoenix app.

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Hey @marceloandrader let me see if I understand the scenario you are trying to make work.

  1. You have an existing PHP app that serves HTTP requests, including SSE.
  2. You have a Phoenix app that runs on a different domain (host)
  3. You want your pages from the PHP app in (1) to include Javascript that talks to (2)?

Last Post!

marceloandrader

marceloandrader

Thank you all, reporting that it worked flawlessly. For the PHP side talking to elixir, I just decided to add an endpoint to receive the message and broadcast it.

Only thing left is authentication, in the examples I see that from the js tries to send a userToken, but in my case I’ll need to create this token in PHP to then send in my js file.

Is there any other implementations besides elixir of this signing method:

Phoenix.Token.sign

?

Where Next?

Popular in Questions Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 130286 1222
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 54006 488
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New

We're in Beta

About us Mission Statement