本文整理汇总了PHP中Daemon类的典型用法代码示例。如果您正苦于以下问题:PHP Daemon类的具体用法?PHP Daemon怎么用?PHP Daemon使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Daemon类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onFileChanged
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);
}
}
}
示例2: onReady
/**
* 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);
}
示例3: stdin
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);
}
示例4: init
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']);
}
}
示例5: init
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);
}
}
示例6: stdin
/**
* 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);
}
}
示例7: getDaemonIds
public function getDaemonIds()
{
if (!$this->daemonIds) {
$cmd = Daemon::model()->getDbConnection()->createCommand('select `id` from `daemon`');
$this->daemonIds = $cmd->queryColumn();
}
return $this->daemonIds;
}
示例8: init
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']);
}
}
示例9: onFrame
/**
* 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.');
});
}
}
示例10: init
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();
}
}
示例11: init
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();
}
示例12: addRoute
/**
* 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;
}
示例13: onFrame
/**
* 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.');
});
}
}
示例14: proxy
/**
* 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);
};
}
示例15: actionLogin
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));
}