PHPackages                             crowdhandler/sdk - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. crowdhandler/sdk

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

crowdhandler/sdk
================

A PHP library for interacting with CrowdHandler

1.0.8(1y ago)06.8k1[1 issues](https://github.com/Crowdhandler/crowdhandler-php-sdk/issues)BSD-3-ClausePHPPHP &gt;= 5.3

Since Mar 29Pushed 8mo agoCompare

[ Source](https://github.com/Crowdhandler/crowdhandler-php-sdk)[ Packagist](https://packagist.org/packages/crowdhandler/sdk)[ Docs](https://www.crowdhandler.com/)[ RSS](/packages/crowdhandler-sdk/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (9)DependenciesVersions (17)Used By (0)

CrowdHandler PHP SDK
====================

[](#crowdhandler-php-sdk)

PHP SDK for interacting with CrowdHandler Public and Private APIs. Extensive functionality for checking and queuing users

Instantiate a Public API client
-------------------------------

[](#instantiate-a-public-api-client)

```
$api = new CrowdHandler\PublicClient($yourPublicKey);

```

Instantiate a new GateKeeper object
-----------------------------------

[](#instantiate-a-new-gatekeeper-object)

#### request details implicit (classic PHP)

[](#request-details-implicit-classic-php)

```
$gatekeeper = new CrowdHandler\GateKeeper($api);

```

The GateKeeper class is a controller for interacting with the user request and the CrowdHandler API and taking appropriate action.

#### using PSR7 Request

[](#using-psr7-request)

```
$request = new \Psr\Http\Message\ServerRequestInterface;
$gatekeeper = new CrowdHandler\GateKeeper($api, request);

```

Out of the box, the GateKeeper inspects superglobals for url, ip, agent etc. But if you prefer, or your framework prefers, you can pass a PSR request.

Options
-------

[](#options)

#### Debug mode

[](#debug-mode)

```
$gatekeeper->setDebug(true);

```

Will log some actions to the PHP error log, and also skip redirects so that you can see what's going on without being redirected constantly. Inspect `$gatekeeper->getRedirectUrl()` to see where you would be redirected.

#### Ignore Urls

[](#ignore-urls)

```
$gatekeeper->setIgnoreUrls($regexp);

```

By default, common assets (png jpg etc) will be excluded from API checks, receiving automatic promotion. If you want you can pass your own regular expression. This will *override* the existing RegExp, so you will need to incorporate assets if necessary.

#### Failover waiting room

[](#failover-waiting-room)

```
$gatekeeper->setSafetyNetSlug('yourslug');

```

By default, if an API call fails, or a malformed response is received, you will be redirected to CrowdHandler's ultimate catch-all waiting room until the API responds with more inforamtion. If you prefer to direct to your own, known, catch-all waiting room under these circumstances (recommended), you can set the slug here.

#### Go your own way

[](#go-your-own-way)

```
$gatekeeper->setToken($_SESSION['token']);

```

By default GateKeeper will inspect and set cookies to retain the users session with CrowdHandler on your site. If you want to manage the session another way you can set the token yourself.

#### IP detection getting it wrong? Set it yourself

[](#ip-detection-getting-it-wrong-set-it-yourself)

```
$gatekeeper->setIP($_SERVER['X-MY-WEIRD-LOADBALANCER-FORWARDS-THE-REAL-IP-LIKE-THIS']);

```

Tracking the user's IP should be a simple thing, but in load-balanced or cloud hosting environments, sometimes you'll get the IP of the load balancer instead of the IP of the user. GateKeeper tries common patterns to detect the IP, including common load balancer patterns, but you can ovverride what it detects by setting explicitly if your setup is more exotic. It's important to track the IP accurately. If the same user is tracked via two IPs they could be blocked erroneously, or simultaneously blocked and not-blocked, depending upon whether they are waiting or transacting.

Check the current request
-------------------------

[](#check-the-current-request)

```
$gatekeeper->checkRequest();

```

This is the heart of the class. It looks at the user's request, checks in with the API and retrieves a result that indicates whether the user should be granted access or be sent to a waiting room.

Set the cookie
--------------

[](#set-the-cookie)

#### Automatic

[](#automatic)

We automatically set the cookie so that the user carries their token with each request.

#### Go your own way

[](#go-your-own-way-1)

```
$_SESSION['ch-id'] = $gatekeeper->result->token;

```

If you don't want to use the standard cookie, you can do your own thing. NB, we do not really recommend using the PHP session for storing the token, as it typically times out after 20 minutes. A user may be in a waiting room for hours and then try hitting a url on your site in a new tab, which could result in you issuing them with a new position at the back of the queue. For this reason a session, or permenant cookie is usually preferable.

Redirect the user if they should wait
-------------------------------------

[](#redirect-the-user-if-they-should-wait)

#### Automatic

[](#automatic-1)

```
$gatekeeper->redirectIfNotPromoted()

```

If this user should be waiting, they will be sent to the correct waiting room. There's no need for you to make a conditional check.

#### Do it yourself

[](#do-it-yourself)

```
if (!$gatekeeper->result->promoted) {
    header('location: '.$gatekeeper->getRedirectUrl(), 302);
    exit;
}

```

If you want to make a conditional check, this is the check you shouild make, and how you can find the URL to redirect them to.

Instantiate a Private API Client
--------------------------------

[](#instantiate-a-private-api-client)

```
$api = new CrowdHandler\PrivateClient($yourPrivateKey);

```

Fetch an array of objects
-------------------------

[](#fetch-an-array-of-objects)

#### All

[](#all)

```
$rs = $api->rooms->get();

```

#### With parameters

[](#with-parameters)

```
$rs = $api->rooms->get(['domainID'=>'dom_y0urk3y']);

```

#### Iterate

[](#iterate)

```
foreach($rs as $room) print $room;

```

Fetch an object
---------------

[](#fetch-an-object)

```
$room = $api->rooms->get('room_your1d');

```

Update an object
----------------

[](#update-an-object)

```
$api->domains->put('dom_y0ur1d', ['rate'=>50, 'autotune'=>true]);

```

Post an object
--------------

[](#post-an-object)

```
$api->templates->post(['name'=>'My Template', 'url'=>'https://mysite.com/wait.html']);

```

Delete an object
----------------

[](#delete-an-object)

```
$api->groups->delete('grp_y0ur1d')

```

More information
----------------

[](#more-information)

#### Knowledge base and API

[](#knowledge-base-and-api)

#### email

[](#email)

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance54

Moderate activity, may be stable

Popularity19

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~182 days

Recently: every ~292 days

Total

9

Last Release

413d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/31acf2077c62baf08b304c7d4bb6888a496d6bf89cb84446454e7308b1a60862?d=identicon)[mchyla-mm](/maintainers/mchyla-mm)

![](https://avatars.githubusercontent.com/u/30068660?v=4)[richard-mutt](/maintainers/richard-mutt)[@Richard-Mutt](https://github.com/Richard-Mutt)

---

Top Contributors

[![carl-wells-crowdhandler](https://avatars.githubusercontent.com/u/61698960?v=4)](https://github.com/carl-wells-crowdhandler "carl-wells-crowdhandler (31 commits)")[![richard-mutt-crowdhandler](https://avatars.githubusercontent.com/u/75749047?v=4)](https://github.com/richard-mutt-crowdhandler "richard-mutt-crowdhandler (26 commits)")[![luke-owen-crowdhandler](https://avatars.githubusercontent.com/u/60788788?v=4)](https://github.com/luke-owen-crowdhandler "luke-owen-crowdhandler (7 commits)")[![kkurasz-mm](https://avatars.githubusercontent.com/u/61418869?v=4)](https://github.com/kkurasz-mm "kkurasz-mm (3 commits)")[![jake-grimley-crowdhandler](https://avatars.githubusercontent.com/u/67647048?v=4)](https://github.com/jake-grimley-crowdhandler "jake-grimley-crowdhandler (2 commits)")[![mchyla-mm](https://avatars.githubusercontent.com/u/60914242?v=4)](https://github.com/mchyla-mm "mchyla-mm (1 commits)")

### Embed Badge

![Health badge](/badges/crowdhandler-sdk/health.svg)

```
[![Health](https://phpackages.com/badges/crowdhandler-sdk/health.svg)](https://phpackages.com/packages/crowdhandler-sdk)
```

###  Alternatives

[abbotton/ios-png-parser

A PHP-based tool for parsing IOS application icons in IPA files

2015.4k1](/packages/abbotton-ios-png-parser)[daodao97/hyperf-watch

hyperf develop hot reload

226.6k2](/packages/daodao97-hyperf-watch)[headsnet/money-bundle

Integrates moneyphp/money into your Symfony application

1116.2k](/packages/headsnet-money-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
