PHPackages                             moesif/moesif-slim - 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. [Logging &amp; Monitoring](/categories/logging)
4. /
5. moesif/moesif-slim

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

moesif/moesif-slim
==================

Moesif Collection/Data Ingestion Middleware for Slim Framework

v1.1.1(9mo ago)1227[1 PRs](https://github.com/Moesif/moesif-slim/pulls)Apache-2.0PHP

Since Jun 16Pushed 9mo ago2 watchersCompare

[ Source](https://github.com/Moesif/moesif-slim)[ Packagist](https://packagist.org/packages/moesif/moesif-slim)[ Docs](https://moesif.com)[ RSS](/packages/moesif-moesif-slim/feed)WikiDiscussions master Synced yesterday

READMEChangelog (3)Dependencies (11)Versions (7)Used By (0)

Moesif Slim Middlware
=====================

[](#moesif-slim-middlware)

[![Built For](https://camo.githubusercontent.com/e832a87024307163b4e835d187fbb629e1ea9622f2356583bfaaca71b813f760/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6275696c74253230666f722d736c696d2d626c75652e737667)](http://www.slimframework.com/)[![Latest Version](https://camo.githubusercontent.com/e61b2a6a0a1f50bdaf85e3bd599236ab680fff16da2f75e415084dfe618df413/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6f657369662f6d6f657369662d736c696d2e737667)](https://packagist.org/packages/moesif/moesif-slim)[![Total Downloads](https://camo.githubusercontent.com/f417c48d5771d8cc5b8fef46377c2ecbe1386a32dda985ace9ac04c6a4255522/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6f657369662f6d6f657369662d736c696d2e737667)](https://packagist.org/packages/moesif/moesif-slim)[![Software License](https://camo.githubusercontent.com/109222cb0d1f59ed2e77b56722653623fa45f93e2bb201a6eef8561d26a52185/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d417061636865253230322e302d677265656e2e737667)](https://raw.githubusercontent.com/Moesif/moesif-slim/master/LICENSE)[![Source Code](https://camo.githubusercontent.com/e0d1d4514ba2cf0c7fc2fe7d03ae65bb95348d0afc1ba8eadca79a370e01cff0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f6d6f657369662f6d6f657369662d736c696d2e7376673f7374796c653d736f6369616c)](https://github.com/moesif/moesif-slim)

[Source Code on GitHub](https://github.com/moesif/moesif-slim)

Middleware for PHP Slim Framework to automatically log API Calls and sends to [Moesif](https://www.moesif.com) for API analytics and log analysis

How to install
--------------

[](#how-to-install)

Via Composer

```
$ composer require moesif/moesif-slim
```

or add 'moesif/moesif-slim' to your composer.json file accordingly.

How to use
----------

[](#how-to-use)

### Add Middleware

[](#add-middleware)

Add to the root level:

```
use Slim\App;
use Slim\Factory\AppFactory;
use Moesif\Middleware\MoesifSlim;

// Create App instance
$app = AppFactory::create();

$moesifOptions = [
    'applicationId' => 'Your Moesif Application Id',
];

$app->addErrorMiddleware(true, true, true);

// Add Moesif Middleware
$middleware = new MoesifSlim($moesifOptions);
$app->add($middleware);
```

To track only certain routes, use route specific middleware setup.

### Setup config

[](#setup-config)

Edit `config/moesif.php` file.

```
// In config/moesif.php

return [
    //
    'applicationId' => 'Your Moesif Application Id',
    'logBody' => true,
];
```

Your Moesif Application Id can be found in the [*Moesif Portal*](https://www.moesif.com/). After signing up for a Moesif account, your Moesif Application Id will be displayed during the onboarding steps.

You can always find your Moesif Application Id at any time by logging into the [*Moesif Portal*](https://www.moesif.com/), click on the top right menu, and then clicking *Installation*.

For other configuration options, see below.

Configuration options
---------------------

[](#configuration-options)

You can define Moesif configuration options in the `config/moesif.php` file. Some of these fields are functions. For options functions that take request and response as input arguments, the request and response objects passed in are [Request](https://www.php-fig.org/psr/psr-7/#321-psrhttpmessageserverrequestinterface) request or [Response](https://www.php-fig.org/psr/psr-7/#33-psrhttpmessageresponseinterface) objects.

#### **`applicationId`**

[](#applicationid)

Type: `String`Required, a string that identifies your application.

#### **`identifyUserId`**

[](#identifyuserid)

Type: `($request, $response) => String`Optional, a function that takes a $request and $response and return a string for userId.

```
// In config/moesif.php

$identifyUserId = function($request, $response) {
    // Your custom code that returns a user id string
    return '12345';
};
```

```
return [
  //
  'identifyUserId' => $identifyUserId
];
```

#### **`identifyCompanyId`**

[](#identifycompanyid)

Type: `($request, $response) => String`Optional, a function that takes a $request and $response and return a string for companyId.

```
// In config/moesif.php

$identifyCompanyId = function($request, $response) {
    # Your custom code that returns a company id string
    return '67890';
};
```

```
return [
  //
  'identifyCompanyId' => $identifyCompanyId
];
```

#### **`identifySessionId`**

[](#identifysessionid)

Type: `($request, $response) => String`Optional, a function that takes a $request and $response and return a string for sessionId. Moesif automatically sessionizes by processing at your data, but you can override this via identifySessionId if you're not happy with the results.

#### **`getMetadata`**

[](#getmetadata)

Type: `($request, $response) => Associative Array`Optional, a function that takes a $request and $response and returns $metdata which is an associative array representation of JSON.

```
// In config/moesif.php

$getMetadata = function($request, $response) {
  return array("foo"=>"Slim Framework example", "boo"=>"custom data");
};

return [
  //
  'getMetadata' => $getMetadata
];
```

#### **`apiVersion`**

[](#apiversion)

Type: `String`Optional, a string to specifiy an API Version such as 1.0.1, allowing easier filters.

#### **`maskRequestHeaders`**

[](#maskrequestheaders)

Type: `$headers => $headers`Optional, a function that takes a $headers, which is an associative array, and returns an associative array with your sensitive headers removed/masked.

```
// In config/moesif.php

$maskRequestHeaders = function($headers) {
    $headers['password'] = '****';
    return $headers;
};

return [
  //
  'maskRequestHeaders' => $maskRequestHeaders
];
```

#### **`maskRequestBody`**

[](#maskrequestbody)

Type: `$body => $body`Optional, a function that takes a $body, which is an associative array representation of JSON, and returns an associative array with any information removed.

```
// In config/moesif.php

$maskRequestBody = function($body) {
    // remove any sensitive information.
    $body['password'] = '****';
    return $body;
};

return [
  //
  'maskRequestBody' => $maskRequestBody
];
```

#### **`maskResponseHeaders`**

[](#maskresponseheaders)

Type: `$headers => $headers`Optional, same as above, but for Responses.

#### **`maskResponseBody`**

[](#maskresponsebody)

Type: `$body => $body`Optional, same as above, but for Responses.

#### **`skip`**

[](#skip)

Type: `($request, $response) => String`Optional, a function that takes a $request and $response and returns true if this API call should be not be sent to Moesif.

#### **`debug`**

[](#debug)

Type: `Boolean`Optional, If true, will print debug messages using Illuminate\\Support\\Facades\\Log

#### **`logBody`**

[](#logbody)

Type: `Boolean`Optional, Default true, Set to false to remove logging request and response body to Moesif.

#### **`disableForking`**

[](#disableforking)

Type: `Boolean`Optional, If true, this will disable forking. For the best performance, the SDK forks a process to send events by default. However, this requires your PHP environment to not have exec disabled via disable\_functions.

Update a Single User
--------------------

[](#update-a-single-user)

Create or update a user profile in Moesif. The metadata field can be any customer demographic or other info you want to store. Only the `user_id` field is required.

```
use Moesif\Middleware\MoesifSlim;

// Only userId is required.
// Campaign object is optional, but useful if you want to track ROI of acquisition channels
// See https://www.moesif.com/docs/api#users for campaign schema
// metadata can be any custom object
$user = array(
    "user_id" => "12345",
    "company_id" => "67890", // If set, associate user with a company object
    "campaign" => array(
        "utm_source" => "google",
        "utm_medium" => "cpc",
        "utm_campaign" => "adwords",
        "utm_term" => "api+tooling",
        "utm_content" => "landing"
    ),
    "metadata" => array(
        "email" => "john@acmeinc.com",
        "first_name" => "John",
        "last_name" => "Doe",
        "title" => "Software Engineer",
        "sales_info" => array(
            "stage" => "Customer",
            "lifetime_value" => 24000,
            "account_owner" => "mary@contoso.com"
        )
    )
);

$middleware = new MoesifSlim(['applicationId' => 'Your Moesif Application Id']);
$middleware->updateUser($user);
```

The `metadata` field can be any custom data you want to set on the user. The `user_id` field is required.

Update Users in Batch
---------------------

[](#update-users-in-batch)

Similar to updateUser, but used to update a list of users in one batch. Only the `user_id` field is required.

```
use Moesif\Middleware\MoesifSlim;

$userA = array(
    "user_id" => "12345",
    "company_id" => "67890", // If set, associate user with a company object
    "campaign" => array(
        "utm_source" => "google",
        "utm_medium" => "cpc",
        "utm_campaign" => "adwords",
        "utm_term" => "api+tooling",
        "utm_content" => "landing"
    ),
    "metadata" => array(
        "email" => "john@acmeinc.com",
        "first_name" => "John",
        "last_name" => "Doe",
        "title" => "Software Engineer",
        "sales_info" => array(
            "stage" => "Customer",
            "lifetime_value" => 24000,
            "account_owner" => "mary@contoso.com"
        )
    )
);

$userB = array(
    "user_id" => "1234",
    "company_id" => "6789", // If set, associate user with a company object
    "campaign" => array(
        "utm_source" => "google",
        "utm_medium" => "cpc",
        "utm_campaign" => "adwords",
        "utm_term" => "api+tooling",
        "utm_content" => "landing"
    ),
    "metadata" => array(
        "email" => "john@acmeinc.com",
        "first_name" => "John",
        "last_name" => "Doe",
        "title" => "Software Engineer",
        "sales_info" => array(
            "stage" => "Customer",
            "lifetime_value" => 24000,
            "account_owner" => "mary@contoso.com"
        )
    )
);

$users = array($userA, $userB);

$middleware = new MoesifSlim(['applicationId' => 'Your Moesif Application Id']);
$middleware->updateUsersBatch($users);
```

The `metadata` field can be any custom data you want to set on the user. The `user_id` field is required.

Update a Single Company
-----------------------

[](#update-a-single-company)

Create or update a company profile in Moesif. The metadata field can be any company demographic or other info you want to store. Only the `company_id` field is required.

```
use Moesif\Middleware\MoesifSlim;

// Only companyId is required.
// Campaign object is optional, but useful if you want to track ROI of acquisition channels
// See https://www.moesif.com/docs/api#update-a-company for campaign schema
// metadata can be any custom object
$company = array(
    "company_id" => "67890",
    "company_domain" => "acmeinc.com", // If domain is set, Moesif will enrich your profiles with publicly available info
    "campaign" => array(
        "utm_source" => "google",
        "utm_medium" => "cpc",
        "utm_campaign" => "adwords",
        "utm_term" => "api+tooling",
        "utm_content" => "landing"
    ),
    "metadata" => array(
        "org_name" => "Acme, Inc",
        "plan_name" => "Free",
        "deal_stage" => "Lead",
        "mrr" => 24000,
        "demographics" => array(
            "alexa_ranking" => 500000,
            "employee_count" => 47
        )
    )
);

$middleware = new MoesifSlim(['applicationId' => 'Your Moesif Application Id']);
$middleware->updateCompany($company);
```

The `metadata` field can be any custom data you want to set on the company. The `company_id` field is required.

Update Companies in Batch
-------------------------

[](#update-companies-in-batch)

Similar to update\_company, but used to update a list of companies in one batch. Only the `company_id` field is required.

```
use Moesif\Middleware\MoesifSlim;

$companyA = array(
    "company_id" => "67890",
    "company_domain" => "acmeinc.com", // If domain is set, Moesif will enrich your profiles with publicly available info
    "campaign" => array(
        "utm_source" => "google",
        "utm_medium" => "cpc",
        "utm_campaign" => "adwords",
        "utm_term" => "api+tooling",
        "utm_content" => "landing"
    ),
    "metadata" => array(
        "org_name" => "Acme, Inc",
        "plan_name" => "Free",
        "deal_stage" => "Lead",
        "mrr" => 24000,
        "demographics" => array(
            "alexa_ranking" => 500000,
            "employee_count" => 47
        )
    )
);

$companies = array($companyA);

$middleware = new MoesifSlim(['applicationId' => 'Your Moesif Application Id']);
$middleware->updateCompaniesBatch($companies);
```

The `metadata` field can be any custom data you want to set on the company. The `company_id` field is required.

An Example Slim App with Moesif Integrated
------------------------------------------

[](#an-example-slim-app-with-moesif-integrated)

[Moesif Slim Example](https://github.com/Moesif/moesif-slim-example)

Other integrations
------------------

[](#other-integrations)

To view more documentation on integration options, please visit **[the Integration Options Documentation](https://www.moesif.com/docs/getting-started/integration-options/).**

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance56

Moderate activity, may be stable

Popularity13

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 80% of commits — single point of failure

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 ~930 days

Total

3

Last Release

295d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/01d3256f8e2dc2c3e1a7934d4b11d9dccc7936c1b80dea9a0880e73d3448eeae?d=identicon)[moesif](/maintainers/moesif)

![](https://www.gravatar.com/avatar/fc618c4daa24676ee9242436cafb63fec92912c550d2c26c09debdd6d00e65c1?d=identicon)[dkm199](/maintainers/dkm199)

---

Top Contributors

[![keyur9](https://avatars.githubusercontent.com/u/9168390?v=4)](https://github.com/keyur9 "keyur9 (4 commits)")[![dgilling](https://avatars.githubusercontent.com/u/9476006?v=4)](https://github.com/dgilling "dgilling (1 commits)")

---

Tags

logmiddlewareapiloggingdebuggingslimMoesif

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/moesif-moesif-slim/health.svg)

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

###  Alternatives

[itsgoingd/clockwork

php dev tools in your browser

5.9k27.6M94](/packages/itsgoingd-clockwork)[rollbar/rollbar

Monitors errors and exceptions and reports them to Rollbar

33723.7M82](/packages/rollbar-rollbar)[moesif/moesif-laravel

Moesif Collection/Data Ingestion Middleware for Laravel

1065.8k](/packages/moesif-moesif-laravel)[analog/analog

Fast, flexible, easy PSR-3-compatible PHP logging package with dozens of handlers.

3451.5M24](/packages/analog-analog)[inpsyde/wonolog

Monolog-based logging package for WordPress.

183617.9k7](/packages/inpsyde-wonolog)[flynsarmy/slim-monolog

Monolog logging support Slim Framework

114476.9k9](/packages/flynsarmy-slim-monolog)

PHPackages © 2026

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