Share via

Web PubSub and Web App (PHP 8.2 / Laravel)

Tengku Aiman 120 Reputation points
2026-05-14T13:53:43.89+00:00

Hello, I want to use Web PubSub as my WebSockets for notifications across the system and want to connect with my Web app. I’m a bit confused on the setting up the connections and using it.

Thank you for your help

Azure Web PubSub
Azure Web PubSub

An Azure service that provides real-time messaging for web applications using WebSockets and the publish-subscribe pattern.


Answer accepted by question author

Golla Venkata Pavani 5,745 Reputation points Microsoft External Staff Moderator
2026-05-14T16:13:25.49+00:00

Hi @Tengku Aiman

Thank you for reaching us regarding the issue that you’d like to use Azure Web PubSub to power real-time notifications in your Laravel (PHP 8.2) app but you’re not sure how to wire up the client/server connections.
Since there is no official PHP SDK, we use a simple and clean pattern: your Laravel app generates connection tokens and publishes messages, while the browser connects directly to Web PubSub.

How It Works

  1. Your Laravel backend authenticates the user and provides a short-lived Client Access URL (with JWT token).
  2. The frontend uses that URL to open a WebSocket connection to Azure Web PubSub.
  3. When something happens in your app, Laravel publishes the notification via REST API, and Web PubSub delivers it instantly to the right clients.

Recommended Implementation Steps:

  1. Create the Web PubSub Resource In the Azure Portal, create a Web PubSub resource and choose a hub name (e.g., notifications). Copy the connection string, this will only be used on your server side.
  2. Backend Setup (Laravel) Store the connection string securely in your environment configuration. Implement a negotiate endpoint that returns a Client Access URL for the authenticated user. Add logic to publish messages (to individual users, groups, or all connections) when notifications need to be sent.
  3. Frontend Setup From the browser, call your Laravel negotiate endpoint to retrieve the access URL. Use it to open a WebSocket connection and listen for incoming messages.
  4. Security Best Practices
    • Never expose the connection string to the client side.
    • Always generate short-lived tokens from your backend.
    • Protect the negotiate endpoint with authentication.

Microsoft Documentation for Reference:

Kindly let us know if the above helps or you need further assistance on this issue.

Please "accept" if the information helped you. This will help us and others in the community as well.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.