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

ActiveLibrary[API Development](/categories/api)

ivanapostic/php-api-client
==========================

PHP client for easy use of the Recombee recommendation API.

v1.3.2(9y ago)181MITPHPPHP &gt;=5.4.0

Since May 16Pushed 8y agoCompare

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

READMEChangelogDependencies (3)Versions (13)Used By (0)

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 ivanapostic/php-api-client

```

or

```
{
    "require": {
        "ivanapostic/php-api-client": "^1.3.2"
    }
}

```

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('client-test', 'jGGQ6ZKa8rQ1zTAyxTc0EMn55YPF7FJLUtaMLhbsGxmvwxgTwXYqmUk5xVZFw98L');

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'
    $recommended = $client->send(new Reqs\UserBasedRecommendation('user-25', 5));

    echo 'Recommended items: ' . implode(',',$recommended) . "\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('client-test', 'jGGQ6ZKa8rQ1zTAyxTc0EMn55YPF7FJLUtaMLhbsGxmvwxgTwXYqmUk5xVZFw98L');
$client->send(new Reqs\ResetDatabase()); //Clear everything from the database

/*
We will use computers as items in this example
Computers have three properties
  - price (floating point number)
  - number of processor cores (integer number)
  - description (string)
*/

// 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'));

# 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')
      ],
      //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.
$recommended = $client->send(new Reqs\ItemBasedRecommendation('computer-6', 5, ['targetUserId' => 'user-42']));
echo 'Recommended items: ' . implode(',',$recommended) . "\n";

// Recommend only computers that have at least 3 cores
$recommended = $client->send(
  new Reqs\ItemBasedRecommendation('computer-6', 5, ['targetUserId' => 'user-42', 'filter' => "'num-cores'>=3"])
  );
echo 'Recommended items with at least 3 processor cores: ' . implode(',',$recommended) . "\n";

// Recommend only items that are more expensive then currently viewed item computer-6 (up-sell)
$recommended = $client->send(
  new Reqs\ItemBasedRecommendation('computer-6', 5,
    ['targetUserId' => 'user-42', 'filter' => "'price' > context_item[\"price\"]"])
  );
echo 'Recommended up-sell items: ' . implode(',',$recommended) . "\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\ItemBasedRecommendation('computer-6', 5,
        ['targetUserId' => 'user-42', '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

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 58.3% 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 ~26 days

Recently: every ~37 days

Total

12

Last Release

3359d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/84d83a2c43a379154a09cb0b333ce112cb600ec605f4e872e1cda19e1bb630d9?d=identicon)[ivanapostic](/maintainers/ivanapostic)

---

Top Contributors

[![OndraFiedler](https://avatars.githubusercontent.com/u/1455425?v=4)](https://github.com/OndraFiedler "OndraFiedler (14 commits)")[![ivanapostic](https://avatars.githubusercontent.com/u/30311579?v=4)](https://github.com/ivanapostic "ivanapostic (6 commits)")[![OndraM](https://avatars.githubusercontent.com/u/793041?v=4)](https://github.com/OndraM "OndraM (3 commits)")[![dudla](https://avatars.githubusercontent.com/u/2787526?v=4)](https://github.com/dudla "dudla (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[razorpay/razorpay

Razorpay PHP Client Library

2024.8M44](/packages/razorpay-razorpay)[pubnub/pubnub

This is the official PubNub PHP SDK repository.

1314.6M17](/packages/pubnub-pubnub)[culqi/culqi-php

Cliente Culqi API para PHP

41356.8k1](/packages/culqi-culqi-php)[ahmadawais/sendy-php-api

Sendy PHP API Wrapper: Complete API interfacing.

8673.5k](/packages/ahmadawais-sendy-php-api)[epayco/epayco-php

Epayco API client for PHP

25187.2k3](/packages/epayco-epayco-php)[yunchuang/appstore-connect-api

sdk for appstore connect api

3865.3k](/packages/yunchuang-appstore-connect-api)

PHPackages © 2026

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