Lots of changes, implemented the base usage. Beware of bugs and unfinished states
This commit is contained in:
parent
0c23fdfac2
commit
f20551857b
27 changed files with 3045 additions and 71 deletions
40
tests/tamer_standalone.php
Normal file
40
tests/tamer_standalone.php
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
use LogLib\Log;
|
||||
use TamerLib\Enums\TamerMode;
|
||||
use TamerLib\Objects\ServerConfiguration;
|
||||
use TamerLib\tm;
|
||||
|
||||
require 'ncc';
|
||||
import('net.nosial.tamerlib');
|
||||
|
||||
// Start as client mode, if no configuration is passed on then
|
||||
// Tamer will spawn its own Redis server and use it.
|
||||
tm::initalize(TamerMode::CLIENT, new ServerConfiguration('127.0.0.1', 6379, null, 0));
|
||||
tm::createWorker(12);
|
||||
|
||||
$total_sleep = 0;
|
||||
$start_time = time();
|
||||
// Start doing programming!
|
||||
// Loop 30 times, each time we will do a job
|
||||
for($i = 0; $i < 30; $i++)
|
||||
{
|
||||
$sleep_time = random_int(5, 10);
|
||||
$total_sleep += $sleep_time;
|
||||
|
||||
/** @noinspection PhpUndefinedMethodInspection */
|
||||
$job_id = tm::sleep($sleep_time);
|
||||
|
||||
// Log the result
|
||||
print(sprintf('Created task %s', $job_id) . PHP_EOL);
|
||||
}
|
||||
|
||||
print('Waiting for jobs to finish...' . PHP_EOL);
|
||||
|
||||
// Wait for all jobs to finish
|
||||
tm::wait(function($job_id, $return){
|
||||
print(sprintf('Task %s finished with return value %s', $job_id, $return) . PHP_EOL);
|
||||
});
|
||||
|
||||
print(sprintf('Total sleep time: %s', $total_sleep) . PHP_EOL);
|
||||
print(sprintf('Total execution time: %s', time() - $start_time) . PHP_EOL);
|
Loading…
Add table
Add a link
Reference in a new issue