Move files around.

This commit is contained in:
Darko
2015-05-28 12:36:00 +02:00
parent a5ea73deec
commit ae0434ac11
1403 changed files with 13 additions and 18 deletions
+63
View File
@@ -0,0 +1,63 @@
<?php
declare(ticks=1);
require_once(__DIR__ . '/../fork_daemon.php');
/* setup forking daemon */
$server = new fork_daemon();
$server->max_children_set(5);
$server->max_work_per_child_set(3);
$server->register_child_run("process_child_run");
$server->register_parent_child_exit("process_child_exit");
$server->register_logging("logger", fork_daemon::LOG_LEVEL_ALL);
test_blocking();
function test_blocking()
{
global $server;
echo "Adding 10 units of work\n";
$data_set = array();
for($i=0; $i<10; $i++) $data_set[] = $i;
shuffle($data_set);
$server->addwork($data_set);
/* process work blocking mode */
$server->process_work(true);
echo "Adding 15 more units of work\n";
$data_set = array();
for($i=10; $i<25; $i++) $data_set[] = $i;
shuffle($data_set);
$server->addwork($data_set);
/* process work blocking mode */
$server->process_work(true);
}
/*
* CALLBACK FUNCTIONS
*/
/* registered call back function */
function process_child_run($data_set, $identifier = "")
{
echo "I'm child working on: " . implode(",", $data_set) . ($identifier == "" ? "" : " (id:$identifier)") . "\n";
sleep(rand(4,8));
}
/* registered call back function */
function process_child_exit($pid, $identifier = "")
{
echo "Child $pid just finished" . ($identifier == "" ? "" : " (id:$identifier)") . "\n";
}
/* registered call back function */
function logger($message)
{
echo "logger: " . $message . PHP_EOL;
}
+78
View File
@@ -0,0 +1,78 @@
<?php
declare(ticks=1);
require_once(__DIR__ . '/../fork_daemon.php');
/* setup forking daemon */
$server = new fork_daemon();
$server->max_children_set(5);
$server->max_work_per_child_set(3);
$server->register_child_run("process_child_run");
$server->register_parent_child_exit("process_child_exit");
$server->register_logging("logger", fork_daemon::LOG_LEVEL_ALL);
test_bucket();
function test_bucket()
{
global $server;
define("BUCKET1", 1);
define("BUCKET2", 2);
$server->add_bucket(BUCKET1);
$server->add_bucket(BUCKET2);
$server->max_children_set(2, BUCKET1);
$server->max_children_set(5, BUCKET2);
$data_set = array();
for($i=0; $i<100; $i++) $data_set[] = $i;
/* add work to bucket 1 */
shuffle($data_set);
$server->addwork($data_set, "", BUCKET1);
/* add work to bucket 2 */
shuffle($data_set);
$server->addwork($data_set, "", BUCKET2);
/* wait until all work allocated */
while ($server->work_sets_count(BUCKET1) > 0 || $server->work_sets_count(BUCKET2) > 0)
{
echo "work set count(1): " . $server->work_sets_count(BUCKET1) . ", count(2): " . $server->work_sets_count(BUCKET2) . "\n";
if ($server->work_sets_count(BUCKET1) > 0) $server->process_work(false, BUCKET1);
if ($server->work_sets_count(BUCKET2) > 0) $server->process_work(false, BUCKET2);
sleep(1);
}
/* wait until all children finish */
while ($server->children_running() > 0)
{
echo "waiting for " . $server->children_running() . " children to finish\n";
sleep(1);
}
}
/*
* CALLBACK FUNCTIONS
*/
/* registered call back function */
function process_child_run($data_set, $identifier = "")
{
echo "I'm child working on: " . implode(",", $data_set) . ($identifier == "" ? "" : " (id:$identifier)") . "\n";
sleep(rand(4,8));
}
/* registered call back function */
function process_child_exit($pid, $identifier = "")
{
echo "Child $pid just finished" . ($identifier == "" ? "" : " (id:$identifier)") . "\n";
}
/* registered call back function */
function logger($message)
{
echo "logger: " . $message . PHP_EOL;
}
@@ -0,0 +1,81 @@
<?php
declare(ticks=1);
require_once(__DIR__ . '/../fork_daemon.php');
/* setup forking daemon */
$server = new fork_daemon();
$server->max_children_set(5);
$server->max_work_per_child_set(3);
$server->register_child_run("process_child_run");
$server->register_parent_child_exit("process_child_exit");
$server->register_logging("logger", fork_daemon::LOG_LEVEL_ALL);
test_identifier();
function test_identifier()
{
global $server;
$server->child_single_work_item_set(true);
$server->max_work_per_child_set(1);
echo "Adding 100 units of work\n";
/* add work */
$data_set = array();
for($i=0; $i<100; $i++) $data_set[] = $i;
shuffle($data_set);
$data_set = array_chunk($data_set, 3);
$i = 0;
foreach ($data_set as $item)
{
$server->addwork($item, "IDn$i");
$i++;
}
echo "Processing work in non-blocking mode\n";
/* process work non blocking mode */
$server->process_work(false);
/* wait until all work allocated */
while ($server->work_sets_count() > 0)
{
echo "work set count: " . $server->work_sets_count() . "\n";
$server->process_work(false);
sleep(1);
}
/* wait until all children finish */
while ($server->children_running() > 0)
{
echo "waiting for " . $server->children_running() . " children to finish\n";
sleep(1);
}
}
/*
* CALLBACK FUNCTIONS
*/
/* registered call back function */
function process_child_run($data_set, $identifier = "")
{
echo "I'm child working on: " . implode(",", $data_set) . ($identifier == "" ? "" : " (id:$identifier)") . "\n";
sleep(rand(4,8));
}
/* registered call back function */
function process_child_exit($pid, $identifier = "")
{
echo "Child $pid just finished" . ($identifier == "" ? "" : " (id:$identifier)") . "\n";
}
/* registered call back function */
function logger($message)
{
echo "logger: " . $message . PHP_EOL;
}
@@ -0,0 +1,71 @@
<?php
declare(ticks=1);
require_once(__DIR__ . '/../fork_daemon.php');
/* setup forking daemon */
$server = new fork_daemon();
$server->max_children_set(5);
$server->max_work_per_child_set(3);
$server->register_child_run("process_child_run");
$server->register_parent_child_exit("process_child_exit");
$server->register_logging("logger", fork_daemon::LOG_LEVEL_ALL);
test_nonblocking();
function test_nonblocking()
{
global $server;
echo "Adding 100 units of work\n";
/* add work */
$data_set = array();
for($i=0; $i<100; $i++) $data_set[] = $i;
shuffle($data_set);
$server->addwork($data_set);
echo "Processing work in non-blocking mode\n";
/* process work non blocking mode */
$server->process_work(false);
/* wait until all work allocated */
while ($server->work_sets_count() > 0)
{
echo "work set count: " . $server->work_sets_count() . "\n";
$server->process_work(false);
sleep(1);
}
/* wait until all children finish */
while ($server->children_running() > 0)
{
echo "waiting for " . $server->children_running() . " children to finish\n";
sleep(1);
}
}
/*
* CALLBACK FUNCTIONS
*/
/* registered call back function */
function process_child_run($data_set, $identifier = "")
{
echo "I'm child working on: " . implode(",", $data_set) . ($identifier == "" ? "" : " (id:$identifier)") . "\n";
sleep(rand(4,8));
}
/* registered call back function */
function process_child_exit($pid, $identifier = "")
{
echo "Child $pid just finished" . ($identifier == "" ? "" : " (id:$identifier)") . "\n";
}
/* registered call back function */
function logger($message)
{
echo "logger: " . $message . PHP_EOL;
}
@@ -0,0 +1,86 @@
<?php
/**
* Sample of passing in work and getting back results using a callback
*/
declare(ticks=1);
require_once(__DIR__ . '/../fork_daemon.php');
/* setup forking daemon */
$server = new fork_daemon();
$server->max_children_set(5);
$server->max_work_per_child_set(3);
$server->register_child_run("process_child_run");
$server->register_parent_child_exit("process_child_exit");
$server->register_logging("logger", fork_daemon::LOG_LEVEL_ALL);
$server->register_parent_results("process_results");
test_nonblocking();
function test_nonblocking()
{
global $server;
echo "Adding 100 units of work\n";
/* add work */
$data_set = array();
for($i=0; $i<100; $i++) $data_set[] = $i;
shuffle($data_set);
$server->addwork($data_set);
echo "Processing work in non-blocking mode\n";
/* process work non blocking mode */
$server->process_work(false);
/* wait until all work allocated */
while ($server->work_sets_count() > 0)
{
echo "work set count: " . $server->work_sets_count() . "\n";
$server->process_work(false);
sleep(1);
}
/* wait until all children finish */
while ($server->children_running() > 0)
{
echo "waiting for " . $server->children_running() . " children to finish\n";
sleep(1);
}
}
/*
* CALLBACK FUNCTIONS
*/
function process_results($results, $identifier = "")
{
echo "Results came back: " . implode(",", $results) . ($identifier == "" ? "" : " (id:$identifier)") . PHP_EOL;
}
/* registered call back function */
function process_child_run($data_set, $identifier = "")
{
echo "I'm child working on: " . implode(",", $data_set) . ($identifier == "" ? "" : " (id:$identifier)") . "\n";
$result = array_sum($data_set);
sleep(rand(1,3));
// return results
return $result;
}
/* registered call back function */
function process_child_exit($pid, $identifier = "")
{
echo "Child $pid just finished" . ($identifier == "" ? "" : " (id:$identifier)") . "\n";
}
/* registered call back function */
function logger($message)
{
echo "logger: " . $message . PHP_EOL;
}
@@ -0,0 +1,92 @@
<?php
/**
* Sample of passing in work and getting back results using a call at the
* end of the child processing
*/
declare(ticks=1);
require_once(__DIR__ . '/../fork_daemon.php');
/* setup forking daemon */
$server = new fork_daemon();
$server->max_children_set(100);
$server->max_work_per_child_set(3);
$server->store_result_set(true);
$server->register_child_run("process_child_run");
$server->register_parent_child_exit("process_child_exit");
$server->register_logging("logger", fork_daemon::LOG_LEVEL_ALL);
// no callback with this method since we check results at the end
test_nonblocking();
// since deferred results, check at the end
$results = $server->get_all_results();
var_dump($results);
echo "Sum: " . array_sum($results) . PHP_EOL;
echo "Count: " . count($results) . PHP_EOL;
function test_nonblocking()
{
global $server;
echo "Adding 100 units of work\n";
/* add work */
$data_set = array();
for($i=0; $i<100; $i++) $data_set[] = $i;
shuffle($data_set);
$server->addwork($data_set);
echo "Processing work in non-blocking mode\n";
echo "Sum: " . array_sum($data_set) . PHP_EOL;
/* process work non blocking mode */
$server->process_work(false);
/* wait until all work allocated */
while ($server->work_sets_count() > 0)
{
echo "work set count: " . $server->work_sets_count() . "\n";
$server->process_work(false);
sleep(1);
}
/* wait until all children finish */
while ($server->children_running() > 0)
{
echo "waiting for " . $server->children_running() . " children to finish\n";
sleep(1);
}
}
/*
* CALLBACK FUNCTIONS
*/
/* registered call back function */
function process_child_run($data_set, $identifier = "")
{
echo "I'm child working on: " . implode(",", $data_set) . ($identifier == "" ? "" : " (id:$identifier)") . "\n";
sleep(rand(1,3));
// just do a sum and return it as the result
$result = array_sum($data_set);
// return results
return $result;
}
/* registered call back function */
function process_child_exit($pid, $identifier = "")
{
echo "Child $pid just finished" . ($identifier == "" ? "" : " (id:$identifier)") . "\n";
}
/* registered call back function */
function logger($message)
{
echo "logger: " . $message . PHP_EOL;
}