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
AnyCable can be used as a WebSocket server for Laravel applications using Laravel Echo and Laravel Broadcasting capabilities. Consider it a drop-in replacement for Laravel Reverb, or Pusher, or whatever you use today.
6
4
7
5
Why choosing AnyCable over Reverb et al?
8
6
9
7
AnyCable is a battle-proofed real-time server that's been in production at scale for many years. It comes with extensive features set (reliability, various protocols support, observability tools, etc.) and it's **free to use**.
10
8
11
-
**NOTE:** Currently, this feature in the preview phase. There is some work in progress (see the limitations below).
9
+
You can use AnyCable server in a [Pusher mode](/anycable-go/pusher.md) or _natively_ using a custom broadcasting and Echo adapter. In the latter, you can benefit from such AnyCable features as streams history and resumable sessions (see [Reliable streams](/anycable-go/reliable_streams.md)).
10
+
11
+
## Pusher mode
12
+
13
+
Switching to AnyCable can be as simple as replacing the command to run a WebSocket server (if you use Reverb):
14
+
15
+
```sh
16
+
# before
17
+
$ REVERB_APP_ID=app-id \
18
+
REVERB_APP_KEY=app-key \
19
+
REVERB_APP_SECRET=app-secret \
20
+
php artisan reverb:start
21
+
22
+
# after
23
+
$ ANYCABLE_PUSHER_APP_ID=app-id \
24
+
ANYCABLE_PUSHER_APP_KEY=app-key \
25
+
ANYCABLE_SECRET=app-secret \
26
+
anycable-go
27
+
```
28
+
29
+
And that's it! AnyCable also runs on port 8080 by default, so no changes required.
30
+
31
+
> To give AnyCable a quick try, consider using our free managed service [AnyCable+](https://plus.anycable.io/cables).
32
+
33
+
To run AnyCable locally, you can use the [anycable-laravel][] package that provides the following command:
34
+
35
+
```sh
36
+
php artisan anycable:server
37
+
```
38
+
39
+
When running with this command, AnyCable automatically recognizes the following Reverb environment variables and uses them: `REVERB_APP_ID`, `REVERB_APP_KEY`, `REVERB_APP_SECRET`.
12
40
13
-
## Getting Started
41
+
## AnyCable mode
42
+
43
+
**IMPORTANT:** This feature is currently in progress. Coming soon!
14
44
15
45
> Check out our demo Laravel application to see the complete example: [laravel-anycable-demo][]
16
46
17
-
First, install the [anycable-laravel][] library:
47
+
To fully benefit from AnyCable features, we recommend switching to use our [client library][anycable-client]. We also provide an Echo adapter that provides a familiar interface while using AnyCable JS SDK under the hood.
48
+
49
+
First, install the [anycable-laravel][] package and configure the broadcasting backend—you will need to authorize private and presence channels and publish events:
18
50
19
51
```sh
20
52
composer require anycable/laravel-broadcaster
@@ -40,46 +72,52 @@ Then, register the `anycable` driver in your `config/broadcasting.php` file:
40
72
],
41
73
```
42
74
43
-
AnyCable supports Pusher protocol, so your client-side code stays the same. For example:
75
+
Now, install the `@anycable/echo` JS package and configure your Echo instance:
76
+
44
77
45
78
```js
46
79
importEchofrom"laravel-echo";
80
+
import { createCable } from"@anycable/web";
81
+
importEchoCablefrom"@anycable/echo";
47
82
48
-
// We use Pusher protocol for now
49
-
importPusherfrom"pusher-js";
50
-
window.Pusher= Pusher;
83
+
// Example options
84
+
constcableOptions= {
85
+
protocol:"actioncable-v1-ext-json"// supports stream history and presence
86
+
}
51
87
52
88
window.Echo=newEcho({
53
-
broadcaster:"reverb", // reverb or pusher would work
The `--pusher_app_key` must be the same as the `VITE_REVERB_APP_KEY` for your client.
72
-
To use public channel, you must also provide the `--public_streams` flag. You can also create an `anycable.toml` configuration file (see [docs](/anycable-go/configuration?id=configuration-files)).
104
+
You can specify AnyCable configuration in the `.env` file:
105
+
106
+
-`ANYCABLE_SECRET=secret`
107
+
-`ANYCABLE_PUBLIC_STREAMS=true` (to enable public channels—they're disable by default)
108
+
109
+
You can also create an `anycable.toml` configuration file to fine-tune your AnyCable server (see [docs](/anycable-go/configuration?id=configuration-files)).
110
+
111
+
**NOTE:** The Artisan command automatically configures [AnyCable broadcasting adapter](/anycable-go/broadcasting.md) to HTTP and enables [the "broker" preset](/anycable-go/reliable_streams.md) (streams history).
73
112
74
113
Alternatively, you can install AnyCable using [other available options](/anycable-go/getting_started?id=installation).
75
114
76
115
That's it! Run your Laravel application, launch AnyCable server, and you should see your Echo client connecting to it and receiving updates.
77
116
78
-
## Limitations
79
-
80
-
- Presence channels are yet to be implemented.
117
+
## Benchmarks
81
118
82
-
- Only HTTP broadcasting adapter for AnyCable is supported for now.
0 commit comments