<?php
/**
 * run with command
 * php start.php start
 */

ini_set('display_errors', 'on');
use Workerman\Worker;

if(strpos(strtolower(PHP_OS), 'win') === 0)
{
    exit("start.php not support windows, please use start_for_win.bat\n");
}

// 检查扩展
if(!extension_loaded('pcntl'))
{
    exit("Please install pcntl extension. See http://doc3.workerman.net/appendices/install-extension.html\n");
}

if(!extension_loaded('posix'))
{
    exit("Please install posix extension. See http://doc3.workerman.net/appendices/install-extension.html\n");
}

// 标记是全局启动
define('GLOBAL_START', 1);

require_once __DIR__ . '/config/config.php';
require_once __DIR__ . '/vendor/autoload.php';

defined('IN_WEB') or define('IN_WEB', true);
define('WWWROOT', dirname(__FILE__).'/');
require_once WWWROOT  . 'core.php';
define( 'PATH_CFG', WWWROOT . 'config/'.$config['sidlist'][1].$isTset.'/');
require_once PATH_CFG . 'config.inc.php';
oo::setConfig( $config); //设置全局变量

// 加载所有配置文件，以便启动服务
//foreach(glob(__DIR__.'/GatewayWorker/Config/*.php') as $start_file){
//    require_once $start_file;
//}

// 加载所有Applications/*/start.php，以便启动所有服务
foreach(glob(__DIR__.'/GatewayWorker/*/start*.php') as $start_file)
{
    require_once $start_file;
}

Worker::$stdoutFile = __DIR__ . '/deBUG/gatewayWorker.txt';

// 运行所有服务
Worker::runAll();
