function mw_create_thread($acc) { $script = __FILE__; $pathToPhp = PHP_OS == 'FreeBSD' ? "/usr/local/bin/php" : "/usr/bin/php"; $pathToPhp = loader::is_windows() ? 'Q:\\xampp\\xampplite\\php\\php.exe ' : $pathToPhp; // start $log_file = loader::fix_path(dirname(__FILE__)) . 'logs/%s.log'; return new Threader("{$pathToPhp} -f {$script}", $acc->id, 'uid' . $acc->id, sprintf($log_file, $acc->id)); }
/** * Register module * @throws modules_exception * @return core_module */ public function register($module, $params = null) { $module_class = isset($params['class']) ? $params['class'] : $module; $module_class = (isset($params['prefix']) ? $params['prefix'] : loader::CLASS_PREFIX) . $module_class; $module_path_orig = loader::DIR_MODULES . $module . '/'; $module_path = loader::get_public(); $module_path .= isset($params['path']) ? $params['path'] : loader::DIR_MODULES . $module; $module_path .= '/'; $module_file = $module_path; $module_file .= (isset($params['file']) ? $params['file'] : 'module') . loader::DOT_PHP; core::dprint(array('module::register %s, %s', $module, $module_class), core::E_DEBUG0); if (!fs::file_exists($module_file)) { core::dprint_r(array($module_class, $module_file)); throw new module_exception('Failed to register module ' . $module . '. File does not exists'); } require_once $module_file; if (!class_exists($module_class, 0)) { throw new module_exception('Cant load module ' . $module . ', wrong config?'); } // autotag module, if alternative class used if (!isset($params['tag']) && !empty($params['class'])) { $params['tag'] = $module; } $module_path = loader::fix_path(loader::get_public() . (!empty($params['chroot']) ? $module_path : $module_path_orig)); $this->set($module, new $module_class($module_path, $params)); $newb = $this->get($module); $newb->init_config($this->_get_module_config($module), abs_config::INIT_APPEND); return $newb; }
// -------- // server require_once "modules/moswar/lib/threader.php"; $script = __FILE__; $pathToPhp = PHP_OS == 'FreeBSD' ? "/usr/local/bin/php" : "/usr/bin/php"; $pathToPhp = loader::is_windows() ? 'Q:\\xampp\\xampplite\\php\\php.exe ' : $pathToPhp; // start $threads = array(); /** * First argument: external script or command (required). * Second argument: arguments that your external script or command will receive (optional). * Third argument: name of thread (optional). */ /** @var mw_accounts_collection */ $accs = core::module('moswar')->get_accounts_handle()->load(); $log_file = loader::fix_path(dirname(__FILE__)) . 'logs/%s.log'; $accs = array(1, 2); foreach ($accs as $acc) { $threads[] = new Threader("{$pathToPhp} -f {$script}", $acc, 'uid' . $acc, sprintf($log_file, $acc)); } //$threads[] = new Threader("$pathToPhp -f $script", 2, 'uid2'); /** * We check if any of the 'active' states of our threads are true; * then we display its output using 'listen'. */ while (1) { $active = false; foreach ($threads as $tid => $t) { if ($t->active) { $buffer = $t->listen(); if ($buffer) {
function get_template_root($template = null) { if (!isset($template)) { return $this->template_root; } return loader::fix_path(loader::get_public() . core::get_instance()->get_cfg_var('site_url') . loader::DIR_TEMPLATES . $template . '/'); }