public function onFileChanged($path) { if (!Daemon::lintFile($path)) { Daemon::log(__METHOD__ . ': Detected parse error in ' . $path); return; } foreach ($this->files[$path] as $k => $subscriber) { if (is_callable($subscriber) || is_array($subscriber)) { call_user_func($subscriber, $path); continue; } if (!isset(Daemon::$process->workers->threads[$subscriber])) { unset($this->files[$path][$k]); continue; } $worker = Daemon::$process->workers->threads[$subscriber]; if (Daemon::$config->autoreimport->value) { if ($worker->connection) { $worker->connection->sendPacket(array('op' => 'importFile', 'path' => $path)); } } else { $worker->signal(SIGUSR2); } } }
function __construct() { $this->params = $this->getArgs(); if (isset($this->params['interval'])) { $this->job_scheduling_interval = $this->params['interval']; } if (isset($this->params['max_workers'])) { $this->max_workers = $this->params['max_workers']; } if (isset($this->params['pid_file_location'])) { $this->pidFileLocation = $this->params['pid_file_location']; } if (isset($this->params['uid'])) { $this->userID = $this->params['uid']; } if (isset($this->params['gid'])) { $this->groupID = $this->params['gid']; } if (isset($this->params['pid_file_location'])) { $this->pidFileLocation = $this->params['pid_file_location']; } $s = owa_coreAPI::serviceSingleton(); $this->jobs = $s->getMap('backgound_jobs'); $this->eq = owa_coreAPI::getEventDispatch(); return parent::__construct(); }
/** * Called when the worker is ready to go * * @return void */ public function onReady() { // Adding listener // ComplexJob - STATE_WAITING $job = new ComplexJob(function ($job) { // ComplexJob - STATE_DONE /*array ( 'bar' => array ( 'job' => 'bar', 'success' => false, 'line' => 63, ), 'foo' => array ( 'job' => 'foo', 'success' => true, 'line' => 84, 'arg' => array ( 'param' => 'value', ), ), 'baz' => array ( 'job' => 'baz', 'success' => false, 'line' => 94, ), )*/ Daemon::log($job->results); }); // Adding listener // ComplexJob - STATE_WAITING $job->addListener(function ($job) { // ComplexJob - STATE_DONE }); // Incapsulate some property in job $job->appInstance = $this; // Adding async job foo $job('foo', $this->foo(array('param' => 'value'))); // Adding with 1 sec delay Timer::add(function ($event) use($job) { // Adding async job bar $job('bar', function ($jobname, $job) { Timer::add(function ($event) use($jobname, $job) { // Job done $job->setResult($jobname, array('job' => 'bar', 'success' => false, 'line' => __LINE__)); $event->finish(); }, 1000.0 * 50); }); // Adding async job baz. Equal $job('baz', $job->appInstance->baz()); $job->addJob('baz', $job->appInstance->baz()); // Run jobs. All listeners will be called when the jobs done // ComplexJob - STATE_RUNNING $job(); $event->finish(); }, 1000000.0 * 1); }
public function stdin($buf) { // from mysqld to client. if (Daemon::$settings['mod' . $this->appInstance->modname . 'protologging']) { Daemon::log('MysqlProxy: Server --> Client: ' . Daemon::exportBytes($buf) . "\n\n"); } $this->downstream->write($buf); }
public function init() { Daemon::$settings += array('mod' . $this->modname . 'listen' => 'tcp://0.0.0.0', 'mod' . $this->modname . 'listenport' => 23, 'mod' . $this->modname . 'enable' => 0); if (Daemon::$settings['mod' . $this->modname . 'enable']) { Daemon::log(__CLASS__ . ' up.'); $this->bindSockets(Daemon::$settings['mod' . $this->modname . 'listen'], Daemon::$settings['mod' . $this->modname . 'listenport']); } }
function __construct($id = null, $daemonize = true, $threads = 1) { parent::__construct($daemonize); if ($id) { $this->set_id($id); } $this->threads = $threads; }
public function init() { Daemon::$settings += array('mod' . $this->modname . 'listen' => 'tcp://0.0.0.0', 'mod' . $this->modname . 'listenport' => 1080, 'mod' . $this->modname . 'auth' => 0, 'mod' . $this->modname . 'username' => 'User', 'mod' . $this->modname . 'password' => 'Password', 'mod' . $this->modname . 'enable' => 0); if (Daemon::$settings['mod' . $this->modname . 'enable']) { Daemon::log(__CLASS__ . ' up.'); $this->bindSockets(Daemon::$settings['mod' . $this->modname . 'listen'], Daemon::$settings['mod' . $this->modname . 'listenport'], TRUE); } }
/** * Called when new data received * @param string New data * @return void */ public function stdin($buf) { Daemon::log(Debug::exportBytes($buf)); while ($c = array_pop($this->callbacks)) { list($cb, $st) = $c; $cb(microtime(true) - $st); } }
public function getDaemonIds() { if (!$this->daemonIds) { $cmd = Daemon::model()->getDbConnection()->createCommand('select `id` from `daemon`'); $this->daemonIds = $cmd->queryColumn(); } return $this->daemonIds; }
public function init() { Daemon::addDefaultSettings(array('mod' . $this->modname . 'listen' => 'tcp://0.0.0.0', 'mod' . $this->modname . 'listenport' => 8818, 'mod' . $this->modname . 'passphrase' => 'secret', 'mod' . $this->modname . 'enable' => 0)); if (Daemon::$settings['mod' . $this->modname . 'enable']) { Daemon::log(__CLASS__ . ' up.'); $this->bindSockets(Daemon::$settings['mod' . $this->modname . 'listen'], Daemon::$settings['mod' . $this->modname . 'listenport']); } }
/** * Called when new frame received. * @param string Frame's contents. * @param integer Frame's type. * @return void */ public function onFrame($data, $type) { if ($data === 'ping') { $this->client->sendFrame('pong', WebSocketSERVER::STRING, function ($client) { Daemon::log('ExampleWebSocket: \'pong\' received by client.'); }); } }
public function init() { Daemon::addDefaultSettings(array('mod' . $this->modname . 'listen' => 'tcp://0.0.0.0', 'mod' . $this->modname . 'listenport' => 843, 'mod' . $this->modname . 'file' => Daemon::$dir . '/conf/crossdomain.xml', 'mod' . $this->modname . 'enable' => 0)); if (Daemon::$settings['mod' . $this->modname . 'enable']) { Daemon::log(__CLASS__ . ' up.'); $this->bindSockets(Daemon::$settings['mod' . $this->modname . 'listen'], Daemon::$settings['mod' . $this->modname . 'listenport']); $this->update(); } }
public static function init() { if (!(self::$supported = extension_loaded('eio'))) { Daemon::log('FS: missing pecl-eio, Filesystem I/O performance compromised. Consider installing pecl-eio.'); return; } self::$fdCache = new CappedCacheStorageHits(self::$fdCacheSize); eio_init(); }
/** * Adds a route if it doesn't exist already. * @param string Route name. * @param mixed Route's callback. * @return boolean Success. */ public function addRoute($route, $cb) { if (isset($this->routes[$route])) { Daemon::log(__METHOD__ . ' Route \'' . $route . '\' is already defined.'); return false; } $this->routes[$route] = $cb; return true; }
/** * Called when new frame received. * @param string Frame's contents. * @param integer Frame's type. * @return void */ public function onFrame($data, $type) { if ($data === 'ping') { $this->client->sendFrame('pong', 'STRING', function ($client) { // optional. called when the frame is transmitted to the client Daemon::log('ExampleWebSocket: \'pong\' received by client.'); }); } }
/** * Returns a proxy callback function with logging for debugging purposes * @param callable $cb Callback * @param mixed $name Data * @return callable */ public static function proxy($cb, $name = null) { static $i = 0; $n = ++$i; Daemon::log('Debug::proxy #' . $n . ': SPAWNED (' . json_encode($name) . ')'); return function (...$args) use($cb, $name, $n) { Daemon::log('Debug::proxy #' . $n . ': CALLED (' . json_encode($name) . ')'); $cb(...$args); }; }
/** * Constructor * * @param string $id the name/id of this daemon * @param int $interval sleep this long before doing everything again * @param int $max_children maximum number of child processes at a time * @param boolean $debug debug output flag * * @return void * **/ function __construct($id = null, $interval = 60, $max_children = 2, $debug = null) { parent::__construct(true); // daemonize $this->_interval = $interval; $this->_max_children = $max_children; $this->_debug = $debug; if (isset($id)) { $this->set_id($id); } }
public static function daemonize($pidfile = false) { if (self::$instance) { echo "Singletons only, please\n"; exit(0); } if (PHP_SAPI !== 'cli') { die; } self::$instance = new self($pidfile); }
public function actionLogin($id = 0) { if (isset($_POST['password'])) { $pw = $_POST['password']; $id = (int) $_POST['server_id']; $server = Server::model()->findByPk((int) $id); if (!$server) { throw new CHttpException(404, Yii::t('mc', 'The requested page does not exist.')); } $this->net2FtpDefines(); global $net2ftp_result, $net2ftp_settings, $net2ftp_globals; require_once dirname(__FILE__) . '/../extensions/net2ftp/main.inc.php'; require_once dirname(__FILE__) . '/../extensions/net2ftp/includes/authorizations.inc.php'; $ftpSv = $this->getFtpServer($server); if (strlen($pw)) { $_SESSION['net2ftp_password_encrypted'] = encryptPassword($pw); $sessKey = 'net2ftp_password_encrypted_' . $ftpSv['ip'] . $this->getUsername($server); unset($_SESSION[$sessKey]); } Yii::log('Logging in to FTP server for server ' . $id); $this->redirect(array('ftpClient/browse', 'id' => $id)); } $ftpUser = FtpUser::model()->findByAttributes(array('name' => Yii::app()->user->name)); $daemons = array(); $serverList = array(); $sel = Yii::t('mc', 'Please select a server'); if ($ftpUser) { $c = new CDbCriteria(); $c->join = 'join `ftp_user_server` on `t`.`id`=`server_id`'; $c->condition = '`user_id`=? and `perms`!=\'\''; $c->params = array((int) $ftpUser->id); $svs = Server::model()->findAll($c); $serverList = array(0 => Yii::t('mc', 'Select')); foreach ($svs as $sv) { $dmn = Daemon::model()->findByPk($sv->daemon_id); $dmnInfo = array('ip' => '', 'port' => ''); if (!$dmn) { $dmnInfo['ip'] = Yii::t('mc', 'No daemon found for this server.'); } else { if (isset($dmn->ftp_ip) && isset($dmn->ftp_port)) { $dmnInfo = array('ip' => $dmn->ftp_ip, 'port' => $dmn->ftp_port); } else { $dmnInfo['ip'] = Yii::t('mc', 'Daemon database not up to date, please run the Multicraft installer.'); } } $daemons[$sv->id] = $dmnInfo; $serverList[$sv->id] = $sv->name; } } else { $serverList = array(0 => Yii::t('mc', 'No FTP account found')); $sel = Yii::t('mc', 'See the "Users" menu of your server for a list of FTP accounts'); } $this->render('login', array('id' => $id, 'havePw' => isset($_SESSION['net2ftp_password_encrypted']), 'serverList' => $serverList, 'daemons' => $daemons, 'sel' => $sel)); }
/** * Constructor. * @return void */ public function init() { if ($this->isEnabled()) { list($class, $name) = explode(':', $this->name . ':'); if (!class_exists($class)) { Daemon::log($class . ' class not exists.'); return; } $this->pool = call_user_func(array($class, 'getInstance'), $name); } }
public function init() { Daemon::addDefaultSettings(array('mod' . $this->modname . 'listen' => 'tcpstream://127.0.0.1:844', 'mod' . $this->modname . 'enable' => 0)); if (Daemon::$settings['mod' . $this->modname . 'enable']) { Daemon::log(__CLASS__ . ' up.'); require_once Daemon::$dir . '/lib/asyncRTEPclient.class.php'; $this->client = new AsyncRTEPclient(); $this->client->addServer(Daemon::$settings[$k = 'mod' . $this->modname . 'addr']); $this->client->trace = TRUE; } }
public function init() { Daemon::addDefaultSettings(array('mod' . $this->modname . 'dbname' => 'chat', 'mod' . $this->modname . 'adminpassword' => '', 'mod' . $this->modname . 'enable' => 0)); if (Daemon::$settings['mod' . $this->modname . 'enable']) { Daemon::log(__CLASS__ . ' up.'); $this->db = Daemon::$appResolver->getInstanceByAppName('MongoClient'); $this->dbname =& Daemon::$settings[$k = 'mod' . $this->modname . 'dbname']; $this->tags = array(); $this->minMsgInterval = 1; } }
public function getConnection($id) { if (@isset($this->connections[$id])) { return $this->connections[$id]; } $daemon = Daemon::model()->findByPk((int) $id); if (!$daemon) { return null; } $con = new McConnectionDemo($this, $id, $daemon->name, $daemon->ip, $daemon->port, ''); return $this->connections[$id] = $con; }
/** * Called when the worker is ready to go. * @return void */ public function onReady() { $this->redis = \PHPDaemon\Clients\Redis\Pool::getInstance(); /*$this->redis->eval("return {'a','b','c', {'d','e','f', {'g','h','i'}} }",0, function($redis) { Daemon::log(Debug::dump($redis->result)); });*/ $this->redis->subscribe('te3st', function ($redis) { Daemon::log(Debug::dump($redis->result)); }); $this->redis->psubscribe('test*', function ($redis) { Daemon::log(Debug::dump($redis->result)); }); }
public static function eventCall($fd, $flags, $args) { $id = $args[0]; if (!isset(Daemon::$process->timeouts[$id])) { Daemon::log(__METHOD__ . ': bad event call.'); return; } $obj = Daemon::$process->timeouts[$id]; call_user_func($obj->cb, $obj); if ($obj->finished) { unset(Daemon::$process->timeouts[$id]); } }
public function init() { Daemon::addDefaultSettings(array('mod' . $this->modname . 'servers' => '127.0.0.1', 'mod' . $this->modname . 'port' => 11211, 'mod' . $this->modname . 'prefix' => '', 'mod' . $this->modname . 'enable' => 0)); $this->prefix =& Daemon::$settings['mod' . $this->modname . 'prefix']; if (Daemon::$settings['mod' . $this->modname . 'enable']) { Daemon::log(__CLASS__ . ' up.'); $servers = explode(',', Daemon::$settings['mod' . $this->modname . 'servers']); foreach ($servers as $s) { $e = explode(':', $s); $this->addServer($e[0], isset($e[1]) ? $e[1] : NULL); } } }
public function init() { Daemon::addDefaultSettings(array('mod' . $this->modname . 'servers' => '127.0.0.1', 'mod' . $this->modname . 'port' => 27017, 'mod' . $this->modname . 'enable' => 0)); $this->cache = Daemon::$appResolver->getInstanceByAppName('MemcacheClient'); if (Daemon::$settings['mod' . $this->modname . 'enable']) { Daemon::log(__CLASS__ . ' up.'); $servers = explode(',', Daemon::$settings['mod' . $this->modname . 'servers']); foreach ($servers as $s) { $e = explode(':', $s); $this->addServer($e[0], isset($e[1]) ? $e[1] : NULL); } } }
public function init() { // fetching the last offer stamp $cursor = Database::jobs()->find(); $cursor->sort(array('stamp' => -1))->limit(1); while ($item = $cursor->getNext()) { $this->laststamp = $item['stamp']; } // initial time of last check is now $this->lastcheck = time(); // initialized. let's say about it Daemon::log('Workbreeze notifier up'); }
public function getFrameType($type) { if (is_int($type)) { return $type; } if ($type === NULL) { $type = 'STRING'; } $frametype = @constant($a = get_class($this) . '::' . $type); if ($frametype === NULL) { Daemon::log(__METHOD__ . ' : Undefined frametype "' . $type . '"'); } return $frametype; }
/** * Called when request iterated. * @return integer Status. */ public function run() { $stime = microtime(TRUE); $this->header('Content-Type: text/html; charset=utf-8'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Server status.</title> </head> <body> <br />Uptime: <b><?php echo Daemon::date_period_text(Daemon::$startTime, time()); ?> </b> <br /><br /><b>State of workers:</b><?php $stat = Daemon::getStateOfWorkers(); ?> <br />Idle: <?php echo $stat['idle']; ?> <br />Busy: <?php echo $stat['busy']; ?> <br />Total alive: <?php echo $stat['alive']; ?> <br />Shutdown: <?php echo $stat['shutdown']; ?> <br />Pre-init: <?php echo $stat['preinit']; ?> <br />Wait-init: <?php echo $stat['waitinit']; ?> <br />Init: <?php echo $stat['init']; ?> <br /> <br />Request took: <?php printf('%f', round(microtime(TRUE) - $stime, 6)); ?> </body> </html> <?php return; }