You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: guides/deployment/deployment.md
+29-29Lines changed: 29 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,35 +14,6 @@ As an example of deploying to other infrastructures, we also discuss four differ
14
14
15
15
Let's explore those steps above one by one.
16
16
17
-
#### Stickiness, Clustering, and the Long-Polling Transport {: .warning}
18
-
19
-
Phoenix supports two types of transports for its Socket implementation: WebSocket, and Long-Polling. When generating a Phoenix project, you can see the default configuration set in the generated `endpoint.ex` file:
This configuration tells Phoenix that both the WebSocket and the Long-Polling options are available, and based on the client's network conditions, Phoenix will first attempt to connect to the WebSocket, falling back to the Long-Poll option after the configured timeout found in the generated `app.js` file:
28
-
29
-
```javascript
30
-
let liveSocket =newLiveSocket("/live", Socket, {
31
-
longPollFallbackMs:2500,
32
-
params: {_csrf_token: csrfToken}
33
-
})
34
-
```
35
-
36
-
This automatic fallback comes with an important caveat. If you want Long-Polling to work properly, your application must either:
37
-
38
-
1. Utilize the Erlang VM's clustering capabilities, so the default `Phoenix.PubSub` adapter can broadcast messages across nodes
39
-
40
-
2. Choose a different `Phoenix.PubSub` adapter (such as `Phoenix.PubSub.Redis`)
41
-
42
-
3. Or your deployment option must implement sticky sessions - ensuring that all requests for a specific session go to the same machine
43
-
44
-
The reason for this is simple. While a WebSocket is a long-lived open connection to the same machine, long-polling works by opening a request to the server, waiting for a timeout or until the open request is fulfilled, and repeating this process. In order to preserve the state of the user's connected socket and to preserve the behaviour of a socket being long-lived, the user's process is kept alive, and each long-poll request attempts to find the user's stateful process. If the stateful process is not reachable, every request will create a new process and a new state, thereby breaking the fact that the socket is long-lived and stateful.
45
-
46
17
## Handling of your application secrets
47
18
48
19
All Phoenix applications have data that must be kept secure, for example, the username and password for your production database, and the secret Phoenix uses to sign and encrypt important information. The general recommendation is to keep those in environment variables and load them into your application. This is done in `config/runtime.exs` (formerly `config/prod.secret.exs` or `config/releases.exs`), which is responsible for loading secrets and configuration from environment variables.
@@ -144,6 +115,35 @@ And that's it. Next, you can use one of our official guides to deploy:
144
115
*[to Fly.io](fly.html), a PaaS that deploys your servers close to your users with built-in distribution support
145
116
* and [to Heroku](heroku.html), one of the most popular PaaS.
146
117
118
+
## Clustering and Long-Polling Transports
119
+
120
+
Phoenix supports two types of transports for its Socket implementation: WebSocket, and Long-Polling. When generating a Phoenix project, you can see the default configuration set in the generated `endpoint.ex` file:
This configuration tells Phoenix that both the WebSocket and the Long-Polling options are available, and based on the client's network conditions, Phoenix will first attempt to connect to the WebSocket, falling back to the Long-Poll option after the configured timeout found in the generated `app.js` file:
129
+
130
+
```javascript
131
+
let liveSocket =newLiveSocket("/live", Socket, {
132
+
longPollFallbackMs:2500,
133
+
params: {_csrf_token: csrfToken}
134
+
})
135
+
```
136
+
137
+
If you are running more than one machine in production, which is the recommended approach in most cases, this automatic fallback comes with an important caveat. If you want Long-Polling to work properly, your application must either:
138
+
139
+
1. Utilize the Erlang VM's clustering capabilities, so the default `Phoenix.PubSub` adapter can broadcast messages across nodes
140
+
141
+
2. Choose a different `Phoenix.PubSub` adapter (such as `Phoenix.PubSub.Redis`)
142
+
143
+
3. Or your deployment option must implement sticky sessions - ensuring that all requests for a specific session go to the same machine
144
+
145
+
The reason for this is simple. While a WebSocket is a long-lived open connection to the same machine, long-polling works by opening a request to the server, waiting for a timeout or until the open request is fulfilled, and repeating this process. In order to preserve the state of the user's connected socket and to preserve the behaviour of a socket being long-lived, the user's process is kept alive, and each long-poll request attempts to find the user's stateful process. If the stateful process is not reachable, every request will create a new process and a new state, thereby breaking the fact that the socket is long-lived and stateful.
146
+
147
147
## Community Deployment Guides
148
148
149
149
*[Render](https://render.com) has first class support for Phoenix applications. There are guides for hosting Phoenix with [Mix releases](https://render.com/docs/deploy-phoenix), [Distillery](https://render.com/docs/deploy-phoenix-distillery), and as a [Distributed Elixir Cluster](https://render.com/docs/deploy-elixir-cluster).
0 commit comments