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)); }
/** * Under construct */ function __construct() { $this->clear(); if (loader::is_windows()) { // where is it? $this->ffmpeg_exe = 'c:\\bin\\flvencoder\\ffmpeg.exe'; $this->flvtool_exe = 'c:\\bin\\flvencoder\\flvtool2.exe u'; } if (PHP_OS == 'FreeBSD') { $this->ffmpeg_exe = str_replace('/bin', '/local/bin', $this->ffmpeg_exe); $this->flvtool_exe = str_replace('/bin', '/local/bin', $this->flvtool_exe); $this->qt_faststart_exe = str_replace('/bin', '/local/bin', $this->qt_faststart_exe); } if (!$this->valid_encoder()) { core::dprint('[video_conv] Invalid encoder', core::E_ERROR); } }
/** * Called in non-debug mode! * Check for errors * * @param mixed $node * @return string */ function get_static_node_path($node) { // @todo on error, $node empty too! $domain = ''; if (!$node) { // this is / index $url = '/'; $domain = $this->get_current_site()->get_domain(); } else { // node $url = $node->get_url(); $domain = $node->get_site()->get_domain(); } core::dprint(array('[!] Generate static %s', $url)); $urls = explode('/', $url); foreach ($urls as &$u) { if (loader::is_windows()) { $u = iconv('UTF-8', 'WINDOWS-1251', $u); // @fixme windows? } } $url = join('/', $urls); if (substr($url, -1, 1) == '/') { $url .= 'index.html'; } $url = loader::get_public() . 'static/' . $domain . '/' . substr($url, 1); return $url; }
/** * constructor * $params goes to ->cfg('options.$') * @throws exception */ public function __construct($params = array()) { self::time_check('core-boot'); // bogus: fix loop with get_instance if (!self::$_instance) { self::$_instance = $this; } $initilize_after_load = $params === true; if (empty($params) && !is_array($params)) { $params = array(); } $cfg_file = @$params['config-file'] ?: 'engine'; $cfg_file = loader::get_docs() . $cfg_file . '.cfg'; if (fs::file_exists($cfg_file)) { // echo('[error] Configuration file not found'); $this->init_config(parse_ini_file($cfg_file, true)); } // override core-config if (!empty($params['config'])) { $this->config = array_merge($this->config, $params['config']); } // multiconfig config/domain.engine.cfg $host = @$_SERVER['HTTP_HOST']; $host = strpos($host, 'www.') === 0 ? substr($host, 4) : $host; if ($this->cfg('multidomain_config', false) && $host) { $host = str_replace(':', '.', $host); // localhost:8002 $host_config = loader::get_docs() . $host . '.engine.cfg'; if (fs::file_exists($host_config)) { $this->init_config(parse_ini_file($host_config, true), abs_config::INIT_APPEND); } } setlocale(LC_ALL, $locale = $this->cfg('locale', 'ru_RU.UTF8')); if (loader::is_windows()) { list($lang, $codeset) = explode('.', $locale); $lang = substr($lang, 0, 2); putenv('LANG=' . $lang . '.' . $codeset); putenv('LANGUAGE=' . $lang . '.' . $codeset); //bind_textdomain_codeset('mydomain', $codeset); } if (fs::file_exists($libs_file = loader::get_docs() . 'libs.cfg')) { self::$system_libs = parse_ini_file($libs_file, true); } self::$libs = new core_libs(); $duagent = $this->cfg('debugger_agent', 'iamdebugger'); // compare only lside of agent, because firephp or something add its stuff to end if (isset($_SERVER['HTTP_USER_AGENT']) && substr($_SERVER['HTTP_USER_AGENT'], 0, strlen($duagent)) === $duagent || !empty($params['debug'])) { self::set_debug(!empty($params['debug']) ? $params['debug'] : $this->cfg('debug', self::E_INFO)); if (!self::is_debug()) { self::register_lib('console', new SatCMS\Modules\Core\Console\FakeConsole()); } else { if (array_key_exists('console', self::$system_libs)) { // load external console self::lib('console'); } else { // bind console (modules/core/console) self::register_lib('console', new Debug_HackerConsole_Main(!$this->cfg('no_console') && !loader::in_shell() && !loader::in_ajax() || loader::in_ajax() && $this->cfg('debug_ajax', false))); } } } else { if (!loader::in_shell()) { self::$_debug_level = false; //@todo fix blank page on errors without debug enabled ini_set('display_errors', 'off'); } else { // enable debug messages in shell self::set_debug($this->cfg('shell_debug_level', self::E_INFO)); } } if (self::is_debug() && (!loader::in_ajax() || $this->cfg('debug_ajax', false)) && !loader::_option(loader::OPTION_TESTING) && class_exists('\\Whoops\\Run')) { $whoops = new \Whoops\Run(); $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler()); $whoops->register(); $this->set_cfg_var('with_debugger', true); } // build module parent::__construct(loader::get_public(loader::DIR_MODULES) . __CLASS__ . '/', array('options' => $params)); if ($initilize_after_load) { $this->init(); } }
/** * Test bootstrap */ error_reporting(E_ALL); ini_set('display_errors', 'on'); test_assertions::$start_time = microtime(1); // this prevent init10 on modules! register_shutdown_function('test_done'); require dirname(__FILE__) . "/../loader.php"; $BOOT_OPTIONS = array(loader::OPTION_TESTING => true, loader::OPTION_CORE_PARAMS => array('config' => array('database' => 'test'))); loader::bootstrap($BOOT_OPTIONS); if (!loader::in_shell()) { die('Tests available only from console' . PHP_EOL); } // fix unicode if (loader::is_windows() && loader::in_shell()) { system('chcp 65001 > NUL'); } /** * Tests api: * * test_head(title) * test_print(var, var, ...) * * test_assert($assert, $title) * test_except(closure, $title) * * test_done - called on shutdown */ /** * Print test head
// -------- // client if (!empty($argv)) { $id = $argv[0]; while (1) { printf("[THREAD][%d]\n", $id); sleep(1 + rand(1, 5)); } return; } // -------- // 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');