memo

memo dayo.

たくさんのごみファイルを作る


■準備
・gomi.php

<?php
// ==============================================
function write_file ($file_name, $file_content, $mode='wb') {
	if (is_file($file_name) === false) {
		touch($file_name);
		chmod($file_name, 0777);
	}

	if (($fp = fopen($file_name, $mode)) === false) {
		return false;
	}
	if ((fwrite($fp, $file_content)) === false) {
		return false;
	}
	if ((fclose($fp)) === false) {
		return false;
	}
	unset($fp);

	return true;
}
// ==============================================
// ---- ini set ----
ini_set('memory_limit', -1); 
ini_set('max_execution_time', 0);

// ---- define ----
define('DIR_GOMI', dirname(__FILE__) . DIRECTORY_SEPARATOR . 'gomi' . DIRECTORY_SEPARATOR);

// ---- make dir ----
if (is_dir(DIR_GOMI) === false) {
	mkdir(DIR_GOMI);
	chmod(DIR_GOMI, 0777);
}

// ---- make file ----
//for ($i = 0; $i < 6382822; $i++) {
for ($i = 0; $i < 100000; $i++) {
	$file_path = DIR_GOMI;
	$zero_pad  = str_pad('' . $i, 9, '0', STR_PAD_LEFT);

	$file_path .= substr($zero_pad, 0, 3);
	$file_path .= DIRECTORY_SEPARATOR;
	if (is_dir($file_path) === false) {
		mkdir($file_path);
		chmod($file_path, 0777);
	}

	$file_path .= substr($zero_pad, 3, 3);
	$file_path .= DIRECTORY_SEPARATOR;
	if (is_dir($file_path) === false) {
		mkdir($file_path);
		chmod($file_path, 0777);
	}

	$file_path .= substr($zero_pad, 6, 3);
	$file_path .= DIRECTORY_SEPARATOR;
	if (is_dir($file_path) === false) {
		mkdir($file_path);
		chmod($file_path, 0777);
	}

	$file_path .= 'a.txt';
	if (write_file($file_path, '0') === false) {
		die($i);
	}

	unset($file_path);
	unset($zero_pad );
}

echo "ok\n";


■実行

php -f gomi.php


■memo
・実行してから寝る。