function save_file($data, $key, $is_file = true) { $dir = build_data_dir(SAVE_DIRNAME); if (!is_dir($dir)) { mkdir($dir, 0777, true); } $data_path = build_data_path(SAVE_DIRNAME, $key); if ($is_file) { move_uploaded_file($data, $data_path); } else { if (is_array($data)) { $data = implode("\r\n", $data); } file_put_contents($data_path, $data); } }
<?php require __DIR__ . '/lib.php'; $c = 0; do { $data = read_queue(); if ($data) { define('SAVE_DIRNAME', $data); $lpath = build_data_path($data, 'input_left'); $rpath = build_data_path($data, 'input_right'); $left = read_as_array($lpath, true); $right = read_as_array($rpath, true); $left = process_array($left); $right = process_array($right); $type_list = array(TYPE_SAME, TYPE_DIFFERENT, TYPE_LEFT_ONLY, TYPE_RIGHT_ONLY); foreach ($type_list as $type) { $result = compare($type, $left, $right); save_result($type, $result); } } else { usleep(100); } } while (++$c < 10000);