<?php

require_once "vendor/autoload.php";
use predictionio\EventClient;
// check Event Server status
$client = new EventClient("j4jIdbq59JsF2f4CXwwkIiVHNFnyNvWXqMqXxcIbQDqFRz5K0fe9e3QfqjKwvW3O");
$response = $client->getStatus();
echo $response;
// set user - generate 10 users
for ($u = 1; $u <= 10; $u++) {
    $response = $client->setUser($u, array('age' => 20 + $u, 'gender' => 'M'));
    print_r($response);
}
// set item - generate 50 items
for ($i = 1; $i <= 50; $i++) {
    $response = $client->setItem($i, array('pio_itypes' => array('1')));
    print_r($response);
}
// record event - each user randomly views 10 items
for ($u = 1; $u <= 10; $u++) {
    for ($count = 0; $count < 10; $count++) {
        $i = rand(1, 50);
        $response = $client->recordUserActionOnItem('view', $u, $i);
        print_r($response);
    }
}
<?php

require_once "vendor/autoload.php";
use predictionio\EventClient;
use predictionio\PredictionIOAPIError;
try {
    // check Event Server status
    $client = new EventClient("j4jIdbq59JsF2f4CXwwkIiVHNFnyNvWXqMqXxcIbQDqFRz5K0fe9e3QfqjKwvW3O");
    $response = $client->getStatus();
    echo $response;
    // set user with event time
    $response = $client->setUser(9, array('age' => 10), '2014-01-01T10:20:30.400+08:00');
    print_r($response);
    // set user
    $response = $client->setUser(8, array('age' => 20, 'gender' => 'M'));
    print_r($response);
    // unset user
    $response = $client->unsetUser(8, array('age' => 20));
    print_r($response);
    // delete user
    $response = $client->deleteUser(9);
    print_r($response);
    // set item with event time
    $response = $client->setItem(3, array('pio_itypes' => array('1')), '2013-12-20T05:15:25.350+08:00');
    print_r($response);
    // set item
    $response = $client->setItem(2, array('pio_itypes' => array('1')));
    print_r($response);
    // unset item
    $response = $client->unsetItem(2, array('pio_itypes' => array('1')));
    print_r($response);
示例#3
-1
<?php

session_start();
require 'vendor/autoload.php';
use predictionio\EventClient;
Flight::register('mdb', 'Mongo', array('mongodb://localhost'));
//Flight::register('prediction', 'predictionio\EventClient');
Flight::register('guzzle', 'GuzzleHttp\\Client');
Flight::map('prediction_client', function () {
    //$accessKey = 'GJBuFYODWTwFBVQ2D2nbBFW5C0iKClNLEMbYGGhDGoZGEtLre62BLwLJlioTEeJP';
    //$client = new EventClient($accessKey, 'http://localhost:7070');
    $predictionio_appkey = "sD13KDmvVn8RVWaxlkuVUS0wxropKJTdUPbm6vWD7BvheZsqmrW0FJHdZa2y7wR2";
    $predictionio_eventserver = "http://127.0.0.1:7070";
    $client = new EventClient($predictionio_appkey, $predictionio_eventserver);
    return $client;
});
Flight::route('GET /', array('Home', 'index'));
Flight::route('GET /movies/recommended', array('Home', 'recommended'));
Flight::route('POST /movie/random', array('Home', 'random'));
Flight::route('/movies/import', array('Admin', 'import'));
Flight::route('/test', function () {
    $accessKey = 'sD13KDmvVn8RVWaxlkuVUS0wxropKJTdUPbm6vWD7BvheZsqmrW0FJHdZa2y7wR2';
    $client = new EventClient($accessKey, 'http://127.0.0.1:7070');
    $response = $client->setUser(2);
    echo 'a';
    print_r($response);
});
Flight::start();