---
sidebar_position: 4
---

# Publishing

Your server sends events to channels with its secret. Browsers can't publish: they send [client events](channels.md#client-events) to each other at most.

**Node**

```ts
await realtime.publish( 'private-orders-42', 'updated', { status: 'paid' } );
```

**PHP**

```php
$realtime->publish( 'private-orders-42', 'updated', [ 'status' => 'paid' ] );

// Laravel: an event that implements ShouldBroadcast, on PrivateChannel( 'orders.42' )
broadcast( new OrderPaid( $order ) )->toOthers();
```

**Python**

```python
realtime.publish("private-orders-42", "updated", {"status": "paid"})
await realtime.apublish("private-orders-42", "updated", {"status": "paid"})   # from async code: FastAPI, Starlette, Django's async views
```

| Argument | |
|---|---|
| `channels` | one name, or up to 100 |
| `event` | any name but `realtime:…` |
| `data` | anything JSON takes, up to 10 KB |
| `except` (Python `except_tab`) | a tab (the browser's `rt.tab`, sent with the request that caused it), which doesn't get it back. Laravel's `toOthers()` takes it from the request's `X-Socket-ID` header |
| `seal` | `false` sends a private or presence channel's data in plain |

- **Sealed by default:** a private or presence channel's data goes sealed with its key, a copy each. Public channels' data goes in plain, together.
- **A refusal throws** a `RealtimeError` with the server's `code` and HTTP `status` ([errors](errors.md#publishing)); Laravel's broadcasting throws a `BroadcastException`. Publish after your own work is saved: a failed publish is a missed live update, not a lost change.

Several events at once, and what a channel holds now:

**Node**

```ts
await realtime.publishBatch( [
    { channels: 'private-orders-42', event: 'updated', data: { status: 'paid' } },
    { channels: 'orders', event: 'count', data: { open: 7 } },
] );   // 10 events a request

const info = await realtime.channelInfo( 'presence-room-7' );   // { subscriptions, members: { count, list } }
```

**PHP**

```php
$realtime->publishBatch( [
    [ 'channels' => 'private-orders-42', 'event' => 'updated', 'data' => [ 'status' => 'paid' ] ],
    [ 'channels' => 'orders', 'event' => 'count', 'data' => [ 'open' => 7 ] ],
] );   // 10 events a request

$info = $realtime->channelInfo( 'presence-room-7' );   // [ 'subscriptions' => …, 'members' => [ 'count' => …, 'list' => … ] ]
```

**Python**

```python
realtime.publish_batch([
    {"channels": "private-orders-42", "event": "updated", "data": {"status": "paid"}},
    {"channels": "orders", "event": "count", "data": {"open": 7}},
])   # 10 events a request

info = realtime.channel_info("presence-room-7")   # {"subscriptions": …, "members": {"count": …, "list": …}}
```
