Apache PredictionIO SDK PHP Incubator

Clone this repo:
  1. 73075a5 Merge pull request #22 from dugwood/patch-1 by Kenneth Chan · 1 year, 6 months ago develop
  2. a1496eb Wrong variable by Yvan · 1 year, 6 months ago
  3. 830e478 update README by Kenneth Chan · 1 year, 7 months ago
  4. c1aa0a5 Merge pull request #19 from mpatnode-si/develop by Kenneth Chan · 1 year, 7 months ago
  5. 9db4bb3 Merge pull request #4 from mpatnode-si/mike-develop by Konstantin Kopachev · 2 years, 2 months ago

PredictionIO PHP SDK

Build Status Scrutinizer Quality Score Code Coverage


Note: This SDK only supports Prediction IO version 0.8.2 or higher.




Issue Tracker


If you are unsure whether a behavior is an issue, bringing it up in the forum is highly encouraged.

Getting Started

By Composer

The easiest way to install PredictionIO PHP client is to use Composer.

  1. Add predictionio/predictionio as a dependency in your project's composer.json file:

         "require": {
             "predictionio/predictionio": "~0.9.0"
  2. Install Composer:

     curl -sS https://getcomposer.org/installer | php -d detect_unicode=Off
  3. Use Composer to install your dependencies:

     php composer.phar install
  4. Include Composer's autoloader in your PHP code


Supported Commands

For a list of supported commands, please refer to the API documentation.


This package is a web service client based on Guzzle. A few quick examples are shown below.

Instantiate PredictionIO API Event Client

use predictionio\EventClient;
$accessKey = 'j4jIdbq59JsF2f4CXwwkIiVHNFnyNvWXqMqXxcIbQDqFRz5K0fe9e3QfqjKwvW3O';
$client = new EventClient($accessKey, 'http://localhost:7070');

Set a User Record from Your App

// assume you have a user with user ID 5
$response = $client->setUser(5);

Set an Item Record from Your App

// assume you have a book with ID 'bookId1' and we assign 1 as the type ID for book
$response = $client->setItem('bookId1', array('itypes' => 1));

Import a User Action (View) form Your App

// assume this user has viewed this book item
$client->recordUserActionOnItem('view', 5, 'bookId1');

Retrieving Prediction Result

// assume you have created an itemrank engine on localhost:8000
// we try to get ranking of 5 items (item IDs: 1, 2, 3, 4, 5) for a user (user ID 7)

$engineClient = new EngineClient('http://localhost:8000');
$response = $engineClient->sendQuery(array('uid'=>7, 'iids'=>array(1,2,3,4,5)));