PHPackages                             slack-php/slack-socket-mode - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. slack-php/slack-socket-mode

ActiveLibrary[API Development](/categories/api)

slack-php/slack-socket-mode
===========================

Provides a a slack-php Socket Mode implementation

0.2.0(4y ago)1033.2k↓39.5%2[1 PRs](https://github.com/slack-php/slack-php-socket-mode/pulls)MITPHP

Since Jun 20Pushed 3y agoCompare

[ Source](https://github.com/slack-php/slack-php-socket-mode)[ Packagist](https://packagist.org/packages/slack-php/slack-socket-mode)[ RSS](/packages/slack-php-slack-socket-mode/feed)WikiDiscussions main Synced yesterday

READMEChangelog (2)Dependencies (4)Versions (3)Used By (0)

Slack PHP – Socket Mode
=======================

[](#slack-php--socket-mode)

This package provides a slack-php `AppServer` implementation that allows an application written for the [Slack App Framework for PHP](https://github.com/slack-php/slack-php-app-framework) to be run in [Socket Mode](https://api.slack.com/apis/connections/socket). Socket Mode uses the websocket protocol to communicate with Slack, and allows you to run an app (even locally) without having to expose it via a public HTTP endpoint. This can be very useful for testing Slack apps in a way that does not violate most work-related firewall restrictions.

**This package should be used for testing only, and is not designed for production use.**

> This Socket Mode implementation uses the [`amphp/websocket-client`](https://amphp.org/websocket-client/) package from [Amp](https://amphp.org/), an awesome collection of PHP packages that make async and event loop style programming in PHP possible. Check it out sometime.

Installation
------------

[](#installation)

- Requires PHP 7.4+
- Use Composer to install: `composer require slack-php/slack-socket-mode`

Usage
-----

[](#usage)

When using Socket Mode, there is no web server serving your app. When you run an app configured for Socket Mode, it establishes a connection to Slack as a websocket client. It maintains that connection to listen for Slack events until it is explicitly terminated (e.g., via `CTRL+C`), Socket Mode is disabled in your app configuration, or an unrecoverable error occurs. This is a different way of running PHP than many aren't used to, so please pay close attention.

When running an app in Slack Mode, you need an "App Token" instead of the typical "Signing Secret". The App Token is specially purposed for making the web socket connection. You can read more about [Socket Mode](https://api.slack.com/apis/connections/socket) in the Slack documentation to learn how to get an App Token.

### Example

[](#example)

This small app responds to the `/cool` slash command.

> Assumptions:
>
> - You have required the Composer autoloader to enable autoloading of the framework files.
> - You have set `SLACK_APP_TOKEN` in the environment (e.g., `putenv("SLACK_APP_TOKEN=foo");`)

```
