Exemplo n.º 1
0
<?php

namespace zyzo\MeteorDDP\tests;

require __DIR__ . '/../vendor/autoload.php';
use zyzo\MeteorDDP\DDPClient;
$client = new DDPClient('localhost', 3000);
$client->connect();
$client->call("foo", array(1));
while (($yo = $client->getResult("foo")) === null) {
    sleep(1);
}
echo 'Result = ' . $yo . PHP_EOL;
$client->stop();
Exemplo n.º 2
0
<?php

require 'vendor/autoload.php';
use zyzo\MeteorDDP\DDPClient;
$client = new DDPClient('localhost', 3000);
$client->connect();
function resultHandler($a)
{
    $i = 10000000;
    while ($i--) {
    }
    echo 'Result = ' . $a . PHP_EOL;
}
$client->asyncCall("foo", array(1), 'resultHandler');
echo 'Doing some work..' . PHP_EOL;
echo 'Doing some work..' . PHP_EOL;
echo 'Doing some work..' . PHP_EOL;
// anonymous function style
$client->asyncCall("foo", array(1), function ($a) {
    resultHandler($a);
});
echo 'Doing some work..' . PHP_EOL;
echo 'Doing some work..' . PHP_EOL;
echo 'Doing some work..' . PHP_EOL;
$i = 100000000;
while ($i--) {
}
$client->stop();
Exemplo n.º 3
0
<?php

require 'vendor/autoload.php';
use zyzo\MeteorDDP\DDPClient;
ini_set('display_errors', 'On');
error_reporting(E_ALL);
DDPClient::enableLog();
$client = new DDPClient('localhost', 3000);
// Must connect to local mongodb before connecting to meteor
$client->connectMongo('localhost:27017', array(), 'test');
// Connect to meteor
$client->connect();
// Subscribe to function Foo
$client->subscribe('Foo', array());
while (1) {
}
Exemplo n.º 4
0
<?php

namespace zyzo\MeteorDDP\tests;

require 'vendor/autoload.php';
use zyzo\MeteorDDP\DDPClient;
$client = new DDPClient('localhost', 3000);
$client->connect();
$client->call("foo", array(1));
while (($yo = $client->getResult("foo")) === null) {
    sleep(1);
}
echo 'Result = ' . $yo . PHP_EOL;
function resultHandler($a)
{
    echo 'Result = ' . $a . PHP_EOL;
}
$client->asyncCall("foo", array(1), function ($a) {
    resultHandler($a);
});
echo 'Do some work...' . PHP_EOL;
$client->asyncCall("foo", array(1), 'zyzo\\MeteorDDP\\tests\\resultHandler');
echo 'Do some work...' . PHP_EOL;
$client->stop();
Exemplo n.º 5
0
 function onMessage($message)
 {
     DDPClient::log('Receiving ' . json_encode($message) . PHP_EOL);
     if ($message === null || !isset($message->msg)) {
         return;
     }
     switch ($message->msg) {
         case 'ping':
             $this->onPing(isset($message->id) ? $message->id : null);
             break;
         case 'result':
             $this->onResult($message);
             break;
         case 'added':
             $this->onAdded($message);
             break;
         case 'changed':
             $this->onChanged($message);
             break;
         case 'removed':
             $this->onRemoved($message);
             break;
         case 'ready':
             $this->onReady($message);
             break;
         default:
             break;
     }
 }