WebSocket Service for 1C-Bitrix and Bitrix24
In our practice, a typical Bitrix e-commerce site updates cart stock with a 2-5 second delay. The customer adds an item, but the system hasn't recalculated availability yet. An hour later, an email arrives: 'item out of stock'. WebSocket solves this by maintaining a persistent connection and delivering data instantly. Push notifications for e-commerce — one of the key scenarios we implement. WebSocket is a standard for bidirectional communication (Wikipedia). We offer choosing the right architecture: Centrifugo, Ratchet, or Node.js. Let's break down what and when to choose, and how to integrate without headaches.
The problem with polling
Instead of the browser asking every N seconds "any new data?", WebSocket keeps a single persistent connection. With 1000 simultaneous users and a 5-second interval, polling creates 200 requests per second — most empty. WebSocket sends data only when it appears, reducing server load by 10-15 times and saving up to 40% of server resources (estimated $500/month savings on typical cloud hosting). Long polling is a compromise but scales worse and consumes more memory. In practice, WebSocket handles up to 10,000 simultaneous connections on a single server without performance loss, with response times under 50ms.
Choosing a WebSocket server for Bitrix
The stack choice determines development speed and maintenance cost. Below is a comparison of three approaches without marketing promises.
Technology comparison
| Criteria | Centrifugo | Ratchet | Node.js + Socket.io |
|---|---|---|---|
| Production readiness | High (out of the box) | Medium (requires refinement) | High (ecosystem ready) |
| Customization flexibility | Low (via API) | High (full control) | Medium (ecosystem) |
| Performance (connections) | ~50,000 (10x more than Ratchet) | ~5,000 | ~100,000 (20x more than Ratchet) |
| Integration complexity | Low (2-3 days) | Medium (1-2 weeks) | Medium (1-2 weeks) |
| PHP support | Via HTTP API | Directly (PHP) | Via Redis |
| Typical cost | Starting from $2,000 | Starting from $3,500 | Starting from $4,000 |
Centrifugo is suitable for a quick start: a ready server with channel authorization, message history, and scaling. You get a production-ready solution in a couple of days, but less flexibility — you need to adapt to its API. Ratchet, on the other hand, gives full control: you write connection logic in PHP, integrate directly with Bitrix. The downside — you'll need to implement authorization and error handling manually. Node.js + Socket.io is for high-load projects with thousands of connections. It's a separate stack, integration via Redis pub/sub, but performance is 2-3 times higher compared to Ratchet.
For a typical e-commerce store with 200 orders per day, Centrifugo is enough. If you need a complex chat with history and moderation — choose Node.js. With a limited budget and full customization — Ratchet. Experience shows that the right choice reduces total cost of ownership by 40%.
Architecture with Centrifugo
Centrifugo is a separate service, Bitrix interacts with it via HTTP API:
Browser ←→ WebSocket ←→ Centrifugo ←→ Redis ↑ Bitrix publishes events When an event occurs in Bitrix (new order, status change) — PHP code publishes to a Centrifugo channel:
$centrifugo = new CentrifugoClient('http://centrifugo:8000', $apiKey); $centrifugo->publish('orders:' . $managerId, [ 'event' => 'new_order', 'order_id' => $orderId, 'customer' => $customerName, 'amount' => $amount, ]); The browser, subscribed to the channel orders:{managerId}, instantly receives the event. Channel authorization via JWT — Centrifugo checks permissions through a Bitrix endpoint.
Architecture with Ratchet
For tighter integration — a custom WebSocket server on Ratchet. Run as a daemon:
php /local/cli/websocket_server.php // websocket_server.php use Ratchet\Server\IoServer; use Ratchet\Http\HttpServer; use Ratchet\WebSocket\WsServer; $server = IoServer::factory( new HttpServer( new WsServer( new BitrixWebSocketHandler() ) ), 8080 ); $server->run(); BitrixWebSocketHandler implements \Ratchet\MessageComponentInterface:
-
onOpen— new connection, authorization -
onMessage— message from client -
onClose— close -
onError— error
Connection storage: SplObjectStorage with mapping user_id → connection. Communication with Bitrix via Redis pub/sub — Bitrix publishes, Ratchet reads and distributes.
How to integrate WebSocket with Bitrix?
Integration consists of several steps. Let's use Centrifugo as an example — the most common choice.
- Install and configure Centrifugo. Run a Docker container, specify API key and JWT secret.
- Set up authorization. Create an endpoint in Bitrix that returns a JWT token for the current user. Centrifugo checks the token on each connection.
- Publish events. In Bitrix event handlers (e.g.,
OnOrderAdd), call the Centrifugo HTTP API to publish to the appropriate channel. - Frontend client. Connect via WebSocket, pass the token, subscribe to channels, and handle messages.
- Deploy with Supervisor and Nginx. Ensure auto-restart and proxying.
Frontend: connecting to WebSocket
const ws = new WebSocket('wss://example.com:8080'); ws.onopen = () => { ws.send(JSON.stringify({ type: 'auth', token: userJwt })); }; ws.onmessage = (event) => { const data = JSON.parse(event.data); if (data.event === 'new_order') { showNotification(`New order #${data.order_id} for ${data.amount} $`); } }; ws.onclose = () => { setTimeout(() => connectWebSocket(), 3000); }; Auto-reconnect with exponential backoff is mandatory. Mobile networks are unstable.
What is included in the work
- Scenario analysis and technology selection
- WebSocket server setup (Centrifugo/Ratchet/Node.js)
- Integration with Bitrix via Redis pub/sub
- Frontend client development (JS, authorization, reconnection)
- Deployment with Supervisor and Nginx
- Connection metrics monitoring
- Architecture and support documentation
- Deliverables: detailed architectural documentation, server access credentials, a 2-hour training session for your team, and 1 month of post-launch support
Development stages
| Stage | Content | Duration |
|---|---|---|
| Technology selection | Centrifugo vs Ratchet vs Node.js, infrastructure assessment | 2–3 days |
| WebSocket server | Basic infrastructure, authorization | 1 week |
| Bitrix integration | Redis pub/sub, event publishing from PHP | 3–5 days |
| Frontend client | JS client, reconnection, event handling | 3–5 days |
| Specific scenarios | Notifications, chat, data updates | 1–2 weeks |
| Deployment and monitoring | Supervisor, Nginx, connection metrics | 3–5 days |
When is WebSocket justified?
WebSocket is justified where a delay of a few seconds is critical for UX. For notifications that can be shown upon the next page transition — it's overkill. We will assess your project for free — just contact us.
To speed up the choice: if you have up to 1000 simultaneous connections and typical scenarios (notifications, cart updates) — choose Centrifugo. If you need a custom protocol or integration with PHP logic — Ratchet. For large-scale chats and collaborations — Node.js. Get a consultation from our engineer — we'll help design the architecture.
With over 5 years of experience and certified Bitrix developers, we guarantee 99.9% uptime for your WebSocket service.







