示例#1
0
<?php

require 'vendor/autoload.php';
use ZeroRPC\Client;
use ZeroRPC\Channel;
$client = new Client("tcp://127.0.0.1:1234");
try {
    $client->should_response_error();
} catch (ZeroRPC\RemoteException $e) {
    print $e;
}
try {
    $client->sleep(3);
} catch (ZeroRPC\TimeoutException $e) {
    print $e;
}
try {
    $client->async("sleep", array(1), $null_);
    $client->async("sleep", array(2), $null_);
    Channel::dispatch();
} catch (ZeroRPC\TimeoutException $e) {
    print $e;
}
示例#2
0
<?php

function __autoload($name)
{
    $file = str_replace('\\', DIRECTORY_SEPARATOR, $name) . '.php';
    include __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . $file;
}
use ZeroRPC\Client as ZeroRPC;
$test = new ZeroRPC('tcp://127.0.0.1:18181');
// Example 1
// This will sleep for ~6 seconds
$start = microtime(true);
print $test->sleep(2) . PHP_EOL;
print $test->sleep(3) . PHP_EOL;
print $test->sleep(1) . PHP_EOL;
print 'Example 1: Slept for a total of ' . (microtime(true) - $start) . ' ms' . PHP_EOL;
// Example 2
// The calls being made in parralel, this will sleep for ~3 seconds
$start = microtime(true);
$test->invoke('sleep', array(2), function ($event) {
    print $event->args[0] . PHP_EOL;
});
$test->invoke('sleep', array(3), function ($event) {
    print $event->args[0] . PHP_EOL;
});
$test->invoke('sleep', array(1), function ($event) {
    print $event->args[0] . PHP_EOL;
});
$test->dispatch();
print 'Example 2: Slept for a total of ' . (microtime(true) - $start) . ' ms' . PHP_EOL;
示例#3
0
文件: time.php 项目: 0rpc/zerorpc-php
<?php

require 'vendor/autoload.php';
use ZeroRPC\Client;
use ZeroRPC\Channel;
$clientA = new Client("tcp://127.0.0.1:1234");
$clientA->setTimeout(3500);
$clientB = new Client("tcp://127.0.0.1:2345");
$clientB->setTimeout(3500);
// normal example
$time = $clientA->strftime("%Y/%m/%d %H:%M:%S");
$clientA->async("strftime", array("%Y/%m/%d %H:%M:%S"), $async_time);
Channel::dispatch();
assert($time == $async_time);
print "Time is {$async_time}!" . PHP_EOL;
// sync example
print "Example 1: start sync call:" . PHP_EOL;
$start = microtime(true);
$clientA->sleep(3);
$clientB->sleep(2);
print 'cost ' . (microtime(true) - $start) . ' s' . PHP_EOL;
// async example
print "Example 2: start async call:" . PHP_EOL;
$start = microtime(true);
$clientA->async("sleep", array(3), $sleep1);
$clientB->async("sleep", array(2), $sleep2);
Channel::dispatch(3500);
print 'cost ' . (microtime(true) - $start) . ' s' . PHP_EOL;