PHPackages                             recombee/php-api-client - 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. recombee/php-api-client

ActiveLibrary[API Development](/categories/api)

recombee/php-api-client
=======================

PHP client for easy use of the Recombee recommendation API.

v6.1.0(4mo ago)242.8M—2.5%12[2 issues](https://github.com/Recombee/php-api-client/issues)6MITPHPPHP &gt;=7.2 || ^8.0

Since May 16Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/Recombee/php-api-client)[ Packagist](https://packagist.org/packages/recombee/php-api-client)[ Docs](https://recombee.com)[ RSS](/packages/recombee-php-api-client/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (39)Used By (6)

Recombee API Client
===================

[](#recombee-api-client)

A PHP client for easy use of the [Recombee](https://www.recombee.com/) recommendation API.

If you don't have an account at Recombee yet, you can create a free account [here](https://www.recombee.com/).

Documentation of the API can be found at [docs.recombee.com](https://docs.recombee.com/).

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

[](#installation)

The best way to install the client is through dependency manager [Composer](https://getcomposer.org/):

```
composer require recombee/php-api-client

```

or

```
{
    "require": {
        "recombee/php-api-client": "^6.1.0"
    }
}

```

Examples
--------

[](#examples)

### Basic example

[](#basic-example)

```
use Recombee\RecommApi\Client;
use Recombee\RecommApi\Requests as Reqs;
use Recombee\RecommApi\Exceptions as Ex;

$client = new Client('--my-database-id--', '--db-private-token--', ['region' => 'us-west']);

const NUM = 100;
const PROBABILITY_PURCHASED = 0.1;

try
{
    // Generate some random purchases of items by users
    $purchase_requests = array();
    for($i=0; $i < NUM; $i++) {
        for($j=0; $j < NUM; $j++) {
            if(mt_rand() / mt_getrandmax() < PROBABILITY_PURCHASED) {

                $request = new Reqs\AddPurchase("user-{$i}", "item-{$j}",
                    ['cascadeCreate' => true] // Use cascadeCreate to create the
                                              // yet non-existing users and items
                );
                array_push($purchase_requests, $request);
            }
        }
    }
    echo "Send purchases\n";
    $res = $client->send(new Reqs\Batch($purchase_requests)); //Use Batch for faster processing of larger data

    // Get 5 recommendations for user 'user-25'
    $response = $client->send(new Reqs\RecommendItemsToUser('user-25', 5));
    echo 'Recommended items: ' . json_encode($response, JSON_PRETTY_PRINT) . "\n";

    // User scrolled down - get next 3 recommended items
    $response = $client->send(new Reqs\RecommendNextItems($response['recommId'], 3));
    echo 'Next recommended items: ' . json_encode($response, JSON_PRETTY_PRINT) . "\n";
}
catch(Ex\ApiException $e)
{
    //use fallback
}
```

### Using property values

[](#using-property-values)

```
use Recombee\RecommApi\Client;
use Recombee\RecommApi\Requests as Reqs;
use Recombee\RecommApi\Exceptions as Ex;

const NUM = 100;
const PROBABILITY_PURCHASED = 0.1;

$client = new Client('--my-database-id--', '--db-private-token--', ['region' => 'ap-se']);
$client->send(new Reqs\ResetDatabase()); // Clear everything from the database

/*
We will use computers as items in this example
Computers have five properties
  - price (floating point number)
  - number of processor cores (integer number)
  - description (string)
  - date from which it is in stock (timestamp)
  - image (url of computer's photo)
*/

// Add properties of items
$client->send(new Reqs\AddItemProperty('price', 'double'));
$client->send(new Reqs\AddItemProperty('num-cores', 'int'));
$client->send(new Reqs\AddItemProperty('description', 'string'));
$client->send(new Reqs\AddItemProperty('in_stock_from', 'timestamp'));
$client->send(new Reqs\AddItemProperty('image', 'image'));

# Prepare requests for setting a catalog of computers
$requests = array();
for($i=0; $i rand(15000, 25000),
        'num-cores' => rand(1, 8),
        'description' => 'Great computer',
        'in_stock_from' => new DateTime('NOW'),
        'image' => "http://examplesite.com/products/{$itemId}.jpg"
      ],
      //optional parameters:
      ['cascadeCreate' => true] // Use cascadeCreate for creating item
                                 // with given itemId, if it doesn't exist]
    );
    array_push($requests, $r);
}

// Send catalog to the recommender system
$result =  $client->send(new Reqs\Batch($requests));
var_dump($result);

// Generate some random purchases of items by users
$requests = array();

for($i=0; $i true]);
           array_push($requests, $r);
        }

// Send purchases to the recommender system
$client->send(new Reqs\Batch($requests));

// Get 5 items related to item computer-6. Personalize them for user-42, who is currently viewing that item.
// Recommend only computers that have at least 3 cores
$recommended = $client->send(
  new Reqs\RecommendItemsToItem('computer-6', 'user-42', 5, ['filter' => "'num-cores'>=3"])
  );
echo 'Recommended items with at least 3 processor cores: ' . json_encode($recommended, JSON_PRETTY_PRINT) . "\n";

// Recommend only items that are more expensive then currently viewed item computer-6 (up-sell)
$recommended = $client->send(
  new Reqs\RecommendItemsToItem('computer-6', 'user-42', 5,
    ['filter' => "'price' > context_item[\"price\"]"])
  );
echo 'Recommended up-sell items: ' . json_encode($recommended, JSON_PRETTY_PRINT) . "\n";

// Filters, boosters and other settings can be set also in the Admin UI (admin.recombee.com)
// when scenario is specified
$recommended = $client->send(
  new Reqs\RecommendItemsToItem('computer-6', 'user-42', 5, ['scenario' => 'product_detail'])
  );

// Perform personalized full-text search with a user's search query (e.g. 'computers')
$matches = $client->send(
  new Reqs\SearchItems('user-42', 'computers', 5, ['scenario' => 'search_top'])
  );
echo 'Matched items: ' . json_encode($matches, JSON_PRETTY_PRINT) . "\n";
```

### Exception handling

[](#exception-handling)

For the sake of brevity, the above examples omit exception handling. However, various exceptions can occur while processing request, for example because of adding an already existing item, submitting interaction of nonexistent user or because of timeout.

We are doing our best to provide the fastest and most reliable service, but production-level applications must implement a fallback solution since errors can always happen. The fallback might be, for example, showing the most popular items from the current category, or not displaying recommendations at all.

Example:

```
use Recombee\RecommApi\Client;
use Recombee\RecommApi\Requests as Reqs;
use Recombee\RecommApi\Exceptions as Ex;

try
{
    $recommended = $client->send(
      new Reqs\RecommendItemsToItem('computer-6', 'user-42', 5,
        ['filter' => "'price' > context_item[\"price\"]"])
    );
}
catch(Ex\ApiTimeoutException $e)
{
    //Handle timeout => use fallback
}
catch(Ex\ResponseException $e)
{
    //Handle errorneous request => use fallback
}
catch(Ex\ApiException $e)
{
    //ApiException is parent of both ResponseException and ApiTimeoutException
}
```

###  Health Score

63

—

FairBetter than 99% of packages

Maintenance76

Regular maintenance activity

Popularity54

Moderate usage in the ecosystem

Community26

Small or concentrated contributor base

Maturity80

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 79.2% 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 ~98 days

Recently: every ~90 days

Total

37

Last Release

130d ago

Major Versions

v1.6.1 → v2.0.02018-02-19

v2.4.0 → v3.0.02020-01-29

v3.2.1 → v4.0.02022-04-20

v4.1.2 → v5.0.02025-01-14

v5.1.1 → v6.0.02025-10-23

PHP version history (4 changes)v1.0PHP &gt;=5.4.0

v1.4.0PHP &gt;=5.3.0

v3.1.0PHP &gt;=7.2.0

v5.0.0PHP &gt;=7.2 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/91b4b512a04269453fd33ca73e4b868e58957415949a6957cfbbaf69e1ede68a?d=identicon)[recombee](/maintainers/recombee)

---

Top Contributors

[![OndraFiedler](https://avatars.githubusercontent.com/u/1455425?v=4)](https://github.com/OndraFiedler "OndraFiedler (42 commits)")[![OndraM](https://avatars.githubusercontent.com/u/793041?v=4)](https://github.com/OndraM "OndraM (3 commits)")[![matyx](https://avatars.githubusercontent.com/u/7956225?v=4)](https://github.com/matyx "matyx (2 commits)")[![MichalDemko](https://avatars.githubusercontent.com/u/49073110?v=4)](https://github.com/MichalDemko "MichalDemko (1 commits)")[![Ndottens](https://avatars.githubusercontent.com/u/45965646?v=4)](https://github.com/Ndottens "Ndottens (1 commits)")[![dudla](https://avatars.githubusercontent.com/u/2787526?v=4)](https://github.com/dudla "dudla (1 commits)")[![staabm](https://avatars.githubusercontent.com/u/120441?v=4)](https://github.com/staabm "staabm (1 commits)")[![lwillems](https://avatars.githubusercontent.com/u/6826563?v=4)](https://github.com/lwillems "lwillems (1 commits)")[![magus424](https://avatars.githubusercontent.com/u/384053?v=4)](https://github.com/magus424 "magus424 (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/recombee-php-api-client/health.svg)

```
[![Health](https://phpackages.com/badges/recombee-php-api-client/health.svg)](https://phpackages.com/packages/recombee-php-api-client)
```

###  Alternatives

[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3731.2M42](/packages/tencentcloud-tencentcloud-sdk-php)[convertkit/convertkitapi

Kit PHP SDK for the Kit API

2167.1k1](/packages/convertkit-convertkitapi)[mapado/rest-client-sdk

Rest Client SDK for hydra API

1125.9k2](/packages/mapado-rest-client-sdk)

PHPackages © 2026

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