//this func accept file's name and return array with unserialize items function serFile($filename) { $list = file($filename); $res = []; foreach ($list as $item) { $item = unserialize($item); $res[$item['ip']] = $item; } return $res; } $list = serFile(ADMIN_LOG); include_once 'proc.php'; if (isset($_POST['itemForShow'])) { $itemForShow = $_POST['itemForShow']; list($info, $tableWay) = getFromFile($itemForShow, $list); } if (isset($_GET['action'])) { $action = strtolower(strip_tags(trim($_GET['action']))); $num = isset($_GET['num']) ? strtolower(strip_tags(trim($_GET['num']))) : false; switch ($action) { case 'cleanway': if ($num) { delWays($num, $list); } break 1; case 'delone': if (count($list) == 1) { delAll(); } elseif ($num) { delOne($num, $list);
} // skipping benchmarks, individual files are infeasible due to storage size /* $repeatedColHeader = 'AAA AAA AAA AAA AAA'; $repeatedData = 'BBB BBB BBB BBB BBB'; $rowCounts = array(1, 10, 100, 1000); $colCounts = array(1, 10, 100, 1000); foreach ($colCounts as $colCount) { foreach ($rowCounts as $rowCount) { $data = array(); $dataRow = array(); for ($i=0; $i<$colCount; ++$i) { $dataRow[$repeatedColHeader . $i] = $repeatedData; } for ($i=0; $i<$rowCount; ++$i) { $data[] = $dataRow; } } } */ $testData = getFromFile('core/getFromFile/small.csv', false); $functions = array('createFileOfRow' => 'readFileDir', 'append' => 'readAppended'); $loc = array('append' => "{$dir}/append.csv", 'createFileOfRow' => "{$dir}/manyFiles"); foreach ($functions as $write => $read) { foreach ($testData as $row) { call_user_func_array($write, array($loc[$write], $row)); } var_dump(call_user_func_array($read, array($loc[$write]))); }
} } return true; } $benchmarks = array(); $iterations = 100; $small = 'core/getFromFile/small.csv'; $big = 'core/getFromFile/big.csv'; $start = microtime(true); for ($i = 0; $i < $iterations; ++$i) { getFromFile($big); } $benchmarks['getFromFile-big'] = microtime(true) - $start; $start = microtime(true); for ($i = 0; $i < $iterations; ++$i) { getFromFile($small); } $benchmarks['getFromFile-small'] = microtime(true) - $start; $start = microtime(true); for ($i = 0; $i < $iterations; ++$i) { readCsvTyson($big); } $benchmarks['readCsvTyson-big'] = microtime(true) - $start; $start = microtime(true); for ($i = 0; $i < $iterations; ++$i) { readCsvTyson($small); } $benchmarks['readCsvTyson-small'] = microtime(true) - $start; $start = microtime(true); for ($i = 0; $i < $iterations; ++$i) { readCsvInline($big);