Refactored Interfaces and implemented Tamer, Gearman's protocol has been refactored by RabbitMQ needs refactoring
This commit is contained in:
parent
6d8d4a75a4
commit
c80b4b39c4
21 changed files with 1103 additions and 360 deletions
57
tests/tamer_client.php
Normal file
57
tests/tamer_client.php
Normal file
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
use Tamer\Abstracts\Mode;
|
||||
use Tamer\Abstracts\ProtocolType;
|
||||
use Tamer\Tamer;
|
||||
|
||||
require 'ncc';
|
||||
|
||||
import('net.nosial.tamerlib', 'latest');
|
||||
|
||||
Tamer::connect(ProtocolType::Gearman, Mode::Client,
|
||||
['127.0.0.1:4730']
|
||||
);
|
||||
|
||||
// Pi calculation (closure)
|
||||
// Add it 10 times
|
||||
for($i = 0; $i < 100; $i++)
|
||||
{
|
||||
Tamer::queueClosure(function() {
|
||||
// Do Pi calculation
|
||||
$pi = 0;
|
||||
$top = 4.0;
|
||||
$bot = 1.0;
|
||||
$minus = true;
|
||||
|
||||
for($i = 0; $i < 1000000; $i++)
|
||||
{
|
||||
if($minus)
|
||||
{
|
||||
$pi -= ($top / $bot);
|
||||
$minus = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
$pi += ($top / $bot);
|
||||
$minus = true;
|
||||
}
|
||||
|
||||
$bot += 2.0;
|
||||
}
|
||||
|
||||
\LogLib\Log::info('net.nosial.tamerlib', sprintf('Pi: %s', $pi));
|
||||
return $pi;
|
||||
});
|
||||
}
|
||||
|
||||
// Sleep function (task)
|
||||
Tamer::queue(\Tamer\Objects\Task::create('sleep', 5, function(\Tamer\Objects\JobResults $data)
|
||||
{
|
||||
echo "Slept for {$data->getData()} seconds \n";
|
||||
}));
|
||||
|
||||
$a = microtime(true);
|
||||
Tamer::run();
|
||||
$b = microtime(true);
|
||||
|
||||
echo "Took " . ($b - $a) . " seconds \n";
|
Loading…
Add table
Add a link
Reference in a new issue