Skip to content

Commit 3584d94

Browse files
committed
+ pusher + upgrade laravel guide
1 parent d735e62 commit 3584d94

2 files changed

Lines changed: 64 additions & 25 deletions

File tree

docs/_sidebar.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
* [Instrumentation](/anycable-go/instrumentation.md)
7676
* [Health checking](/anycable-go/health_checking.md)
7777
* [Tracing](/anycable-go/tracing.md)
78+
* [Pusher support](/anycable-go/pusher.md)
7879
* [OS Tuning](/anycable-go/os_tuning.md)
7980
* [Signed streams (Hotwire / Cable Ready)](/anycable-go/signed_streams.md)
8081
* [Embedded NATS](/anycable-go/embedded_nats.md)

docs/guides/laravel.md

Lines changed: 63 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,52 @@
11
# Using AnyCable with Laravel
22

3-
<p class="preview-badge-header"></p>
4-
53
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.
64

75
Why choosing AnyCable over Reverb et al?
86

97
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**.
108

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`.
1240

13-
## Getting Started
41+
## AnyCable mode
42+
43+
**IMPORTANT:** This feature is currently in progress. Coming soon!
1444

1545
> Check out our demo Laravel application to see the complete example: [laravel-anycable-demo][]
1646
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:
1850

1951
```sh
2052
composer require anycable/laravel-broadcaster
@@ -40,46 +72,52 @@ Then, register the `anycable` driver in your `config/broadcasting.php` file:
4072
],
4173
```
4274

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+
4477

4578
```js
4679
import Echo from "laravel-echo";
80+
import { createCable } from "@anycable/web";
81+
import EchoCable from "@anycable/echo";
4782

48-
// We use Pusher protocol for now
49-
import Pusher from "pusher-js";
50-
window.Pusher = Pusher;
83+
// Example options
84+
const cableOptions = {
85+
protocol: "actioncable-v1-ext-json" // supports stream history and presence
86+
}
5187

5288
window.Echo = new Echo({
53-
broadcaster: "reverb", // reverb or pusher would work
54-
key: import.meta.env.VITE_REVERB_APP_KEY,
55-
wsHost: import.meta.env.VITE_REVERB_HOST,
56-
wsPort: import.meta.env.VITE_REVERB_PORT ?? 80,
57-
wssPort: import.meta.env.VITE_REVERB_PORT ?? 443,
58-
forceTLS: (import.meta.env.VITE_REVERB_SCHEME ?? "https") === "https",
59-
enabledTransports: ["ws", "wss"],
89+
broadcaster: EchoCable,
90+
cable: createCable(cableOptions),
91+
// other configuration options such as auth, etc
6092
});
6193
```
6294

63-
Just make sure you point to to the AnyCable server (locally it runs on the same host and port as Reverb).
95+
By default, AnyCable client looks up a WebSocket server URL from the `<meta name="cable-url">` tag on the page.
96+
You can also specify it explicitly in the options.
6497

6598
Finally, install AnyCable server. We provide a convenient Artisan command that automatically downloads (when necessary) and runs the server:
6699

67100
```sh
68-
php artisan anycable:server -- --pusher_app_key=my-app-key
101+
php artisan anycable:server
69102
```
70103

71-
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).
73112

74113
Alternatively, you can install AnyCable using [other available options](/anycable-go/getting_started?id=installation).
75114

76115
That's it! Run your Laravel application, launch AnyCable server, and you should see your Echo client connecting to it and receiving updates.
77116

78-
## Limitations
79-
80-
- Presence channels are yet to be implemented.
117+
## Benchmarks
81118

82-
- Only HTTP broadcasting adapter for AnyCable is supported for now.
119+
TBD
83120

84121
[anycable-laravel]: https://github.com/anycable/anycable-laravel
85-
[laravel-anycable-demo]: https://github.com/anycable/laravel-anycable-demo
122+
[laravel-anycable-demo]: https://github.com/anycable/larachat
123+
[anycable-client]: https://github.com/anycable/anycable-client

0 commit comments

Comments
 (0)