/**
* @param $p
*/
protected function onPacket($p)
{
if ($p['op'] === 'spawnInstance') {
$fullname = $p['appfullname'];
$fullname = str_replace('-', ':', $fullname);
if (mb_orig_strpos($fullname, ':') === false) {
$fullname .= ':';
}
list($app, $name) = explode(':', $fullname, 2);
Daemon::$appResolver->getInstance($app, $name, true, true);
} elseif ($p['op'] === 'importFile') {
if (!Daemon::$config->autoreimport->value) {
Daemon::$process->gracefulRestart();
return;
}
$path = $p['path'];
Timer::add(function ($event) use($path) {
if (Daemon::supported(Daemon::SUPPORT_RUNKIT_IMPORT)) {
//Daemon::log('--start runkit_import('.$path.')');
runkit_import($path, RUNKIT_IMPORT_FUNCTIONS | RUNKIT_IMPORT_CLASSES | RUNKIT_IMPORT_OVERRIDE);
//Daemon::log('--end runkit_import('.$path.')');
} else {
$this->appInstance->log('Cannot import \'' . $path . '\': runkit_import is not callable.');
}
$event->finish();
}, 5);
} elseif ($p['op'] === 'call') {
if (mb_orig_strpos($p['appfullname'], ':') === false) {
$p['appfullname'] .= ':';
}
list($app, $name) = explode(':', $p['appfullname'], 2);
if ($app = Daemon::$appResolver->getInstance($app, $name)) {
$app->RPCall($p['method'], $p['args']);
}
}
}