private static function load_config() { $config = snarf_scope(SERVER_ROOT . '/config.php'); $config['address'] = $address = getArg('a', 'address', get($config, 'ip', '0.0.0.0')); $port = get($config, 'port', 10000); if (strpos($address, ':') !== false) { $parts = explode(':', $address); $address = $parts[0]; $port = (int) $parts[1]; } $config['port'] = getArg('p', 'port', $port); self::$config = $config; }
/* * copyright Ryan Day 2010 * http://ryanday.org * dual licensed gpl and mit */ error_reporting(E_ALL); define('SERVER_ROOT', dirname(__FILE__)); define('MODULE_PATH', SERVER_ROOT . '/modules'); require SERVER_ROOT . '/lib/server.php'; require SERVER_ROOT . '/lib/response.php'; server::init($sockets, $clients); if (($listen = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) === false) { die("socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n"); } socket_set_option($listen, SOL_SOCKET, SO_REUSEADDR, 1); if (socket_bind($listen, server::config('address'), server::config('port')) === false) { die("socket_bind() failed: reason: " . socket_strerror(socket_last_error($listen)) . "\n"); } if (socket_listen($listen, 5) === false) { die(" socket_listen() failed: reason: " . socket_strerror(socket_last_error($listen)) . "\n"); } $sockets[] = $listen; $clients[] = null; do { $read = $sockets; $write = null; $except = null; $r = socket_select($read, $write, $except, null); if ($r === false) { $err = socket_strerror(socket_last_error()); echo "[ERROR] socket_select() failed, reason: {$err}\n";