<?php include_once 'common.inc.php'; t::clearAll(); $count = 100; $data = range(0, $count); t::i(null, "Control Thread START"); $test = new MapReduce(); $test->setSize(10); $test->setMaxThread(100); $test->passPhraseToChild(true); $test->setData($data); $test->setMapperName("data"); $test->setPhraseName("INIT_SUM"); $test->clearReducer(); $test->clearDefaultReducer(); $test->addDefaultReducer("http://cto.gcgchina.com/t/sample.child.php"); $test->addReducer(1, "http://cto.gcgchina.com/t/sample.child.php"); $result = $test->execute(1); print_r($result); $test->setData(range(0, $result['result'][0])); $test->setMapperName("data"); $test->setPhraseName("SUM_SUM"); $test->clearReducer(); $test->clearDefaultReducer(); $test->addDefaultReducer("http://cto.gcgchina.com/t/sample.child.php"); $test->addReducer(2, "http://cto.gcgchina.com/t/sample.child.php"); $result = $test->execute(1); t::i(null, "Control Thread END"); print_r($result);
$id = Thread::getChildThreadID(); $phrase = Thread::getChildPhrase(); $name = Thread::getPhraseName(); $myname = basename($_SERVER[PHP_SELF]); t::i($id, $myname . "\t " . $name . " ENTER THREAD"); switch ($name) { case "INIT_SUM": $data = Thread::getChildParams("data"); $subtotal = 0; foreach ($data as $i) { $subtotal += $i; } if ($phrase == 1) { t::i($id, "Specified reducer at phrase " . $phrase); } echo $subtotal; break; case "SUM_SUM": $data = Thread::getChildParams("data"); $subtotal = 0; foreach ($data as $i) { $subtotal += $i; } if ($phrase == 2) { t::i($id, "Specified reducer at phrase " . $phrase); } echo $subtotal; break; } t::i($id, $myname . "\t " . $name . " COMPLETE: " . $subtotal);