protected function init()
{
// make sure we have a target file specified
if (empty($_SERVER['argv'][1])) {
$this->outln("Please specify a targets file; e.g., './target/all.ini'.");
exit(1);
} else {
$targets_file = $_SERVER['argv'][1];
}
// does the targets file exist?
$realpath = realpath($targets_file);
if (! $realpath || ! file_exists($realpath) || ! is_readable($realpath)) {
$this->outln("Targets file '$targets_file' does not exist or is not readable.");
exit(1);
}
// retain real path to targets file
$targets_file = $realpath;
// root directory
$base_dir = dirname(dirname(__DIR__));
// the ini file with property values
$data = parse_ini_file("{$base_dir}/config.ini");
// what properties to load?
$vars = array_keys(get_class_vars(get_class($this)));
// set all available properties
foreach ($vars as $var) {
if (array_key_exists($var, $data)) {
$this->$var = $data[$var];
}
}
// massage the concurrency levels
$this->concurrent = explode(',', $this->concurrent);
// read in the targets file
if (substr($targets_file, -4) == '.ini') {
// a .ini file with "name = path"
$this->targets = parse_ini_file($targets_file);
} else {
// a non-ini file with one target URI per line
$keys = file($targets_file);
$vals = array_fill(0, count($keys), null);
$this->targets = array_combine($keys, $vals);
}
// make a directory for logs
$time = date("Y-m-d\TH:i:s");
$this->log_dir = "{$base_dir}/log/{$time}";
@mkdir($this->log_dir, 0777, true);
// reset the req/sec data
$this->req_sec = array();
}