本文整理汇总了PHP中PhutilServiceProfiler::getInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP PhutilServiceProfiler::getInstance方法的具体用法?PHP PhutilServiceProfiler::getInstance怎么用?PHP PhutilServiceProfiler::getInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhutilServiceProfiler
的用法示例。
在下文中一共展示了PhutilServiceProfiler::getInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* Execute this command.
*
* @return int Error code returned by the subprocess.
*
* @task command
*/
public function execute()
{
$command = $this->command;
$profiler = PhutilServiceProfiler::getInstance();
$call_id = $profiler->beginServiceCall(array('type' => 'exec', 'subtype' => 'passthru', 'command' => $command));
$spec = array(STDIN, STDOUT, STDERR);
$pipes = array();
if ($command instanceof PhutilCommandString) {
$unmasked_command = $command->getUnmaskedString();
} else {
$unmasked_command = $command;
}
$env = $this->env;
$cwd = $this->cwd;
$options = array();
if (phutil_is_windows()) {
// Without 'bypass_shell', things like launching vim don't work properly,
// and we can't execute commands with spaces in them, and all commands
// invoked from git bash fail horridly, and everything is a mess in
// general.
$options['bypass_shell'] = true;
}
$trap = new PhutilErrorTrap();
$proc = @proc_open($unmasked_command, $spec, $pipes, $cwd, $env, $options);
$errors = $trap->getErrorsAsString();
$trap->destroy();
if (!is_resource($proc)) {
throw new Exception(pht('Failed to passthru %s: %s', 'proc_open()', $errors));
}
$err = proc_close($proc);
$profiler->endServiceCall($call_id, array('err' => $err));
return $err;
}
示例2: dispatchEvent
public static function dispatchEvent(PhutilEvent $event)
{
$instance = self::getInstance();
$listeners = idx($instance->listeners, $event->getType(), array());
$global_listeners = idx($instance->listeners, PhutilEventType::TYPE_ALL, array());
// Merge and deduplicate listeners (we want to send the event to each
// listener only once, even if it satisfies multiple criteria for the
// event).
$listeners = array_merge($listeners, $global_listeners);
$listeners = mpull($listeners, null, 'getListenerID');
$profiler = PhutilServiceProfiler::getInstance();
$profiler_id = $profiler->beginServiceCall(array('type' => 'event', 'kind' => $event->getType(), 'count' => count($listeners)));
$caught = null;
try {
foreach ($listeners as $listener) {
if ($event->isStopped()) {
// Do this first so if someone tries to dispatch a stopped event it
// doesn't go anywhere. Silly but less surprising.
break;
}
$listener->handleEvent($event);
}
} catch (Exception $ex) {
$profiler->endServiceCall($profiler_id, array());
throw $ex;
}
$profiler->endServiceCall($profiler_id, array());
}
示例3: phutil_passthru
/**
* Execute a command which takes over stdin, stdout and stderr, similar to
* passthru(), but which preserves TTY semantics, escapes arguments, and is
* traceable.
*
* @param string sprintf()-style command pattern to execute.
* @param ... Arguments to sprintf pattern.
* @return int Return code.
* @group exec
*/
function phutil_passthru($cmd)
{
$args = func_get_args();
$command = call_user_func_array('csprintf', $args);
$profiler = PhutilServiceProfiler::getInstance();
$call_id = $profiler->beginServiceCall(array('type' => 'exec', 'subtype' => 'passthru', 'command' => $command));
$spec = array(STDIN, STDOUT, STDERR);
$pipes = array();
if (phutil_is_windows()) {
// Without 'bypass_shell', things like launching vim don't work properly,
// and we can't execute commands with spaces in them, and all commands
// invoked from git bash fail horridly, and everything is a mess in general.
$options = array('bypass_shell' => true);
$proc = @proc_open($command, $spec, $pipes, null, null, $options);
} else {
$proc = @proc_open($command, $spec, $pipes);
}
if ($proc === false) {
$err = 1;
} else {
$err = proc_close($proc);
}
$profiler->endServiceCall($call_id, array('err' => $err));
return $err;
}
示例4: didReceiveResult
protected function didReceiveResult($result)
{
if ($this->profilerCallID !== null) {
$profiler = PhutilServiceProfiler::getInstance();
$profiler->endServiceCall($this->profilerCallID, array());
}
list($status, $body, $headers) = $result;
if ($status->isError()) {
throw $status;
}
$raw = $body;
$shield = 'for(;;);';
if (!strncmp($raw, $shield, strlen($shield))) {
$raw = substr($raw, strlen($shield));
}
$data = null;
try {
$data = phutil_json_decode($raw);
} catch (PhutilJSONParserException $ex) {
throw new PhutilProxyException(pht('Host returned HTTP/200, but invalid JSON data in response to ' . 'a Conduit method call.'), $ex);
}
if ($data['error_code']) {
throw new ConduitClientException($data['error_code'], $data['error_info']);
}
$result = $data['result'];
$result = $this->client->didReceiveResponse($this->conduitMethod, $result);
return $result;
}
示例5: didReceiveResult
protected function didReceiveResult($result)
{
if ($this->profilerCallID !== null) {
$profiler = PhutilServiceProfiler::getInstance();
$profiler->endServiceCall($this->profilerCallID, array());
}
list($status, $body, $headers) = $result;
if ($status->isError()) {
throw $status;
}
$raw = $body;
$shield = 'for(;;);';
if (!strncmp($raw, $shield, strlen($shield))) {
$raw = substr($raw, strlen($shield));
}
$data = json_decode($raw, true);
if (!is_array($data)) {
throw new Exception("Host returned HTTP/200, but invalid JSON data in response to " . "a Conduit method call:\n{$raw}");
}
if ($data['error_code']) {
throw new ConduitClientException($data['error_code'], $data['error_info']);
}
$result = $data['result'];
$result = $this->client->didReceiveResponse($this->conduitMethod, $result);
return $result;
}
示例6: deleteFile
/**
* Delete a blob from Amazon S3.
*/
public function deleteFile($handle)
{
AphrontWriteGuard::willWrite();
$s3 = $this->newS3API();
$profiler = PhutilServiceProfiler::getInstance();
$call_id = $profiler->beginServiceCall(array('type' => 's3', 'method' => 'deleteObject'));
$s3->deleteObject($this->getBucketName(), $handle);
$profiler->endServiceCall($call_id, array());
}
示例7: deleteFile
/**
* Delete a blob from Amazon S3.
*/
public function deleteFile($handle)
{
$s3 = $this->newS3API();
AphrontWriteGuard::willWrite();
$profiler = PhutilServiceProfiler::getInstance();
$call_id = $profiler->beginServiceCall(array('type' => 's3', 'method' => 'deleteObject'));
$s3->setParametersForDeleteObject($handle)->resolve();
$profiler->endServiceCall($call_id, array());
}
示例8: phutil_passthru
/**
* Execute a command which takes over stdin, stdout and stderr, similar to
* passthru(), but which preserves TTY semantics, escapes arguments, and is
* traceable.
*
* @param string sprintf()-style command pattern to execute.
* @param ... Arguments to sprintf pattern.
* @return int Return code.
* @group exec
*/
function phutil_passthru($cmd)
{
$args = func_get_args();
$command = call_user_func_array('csprintf', $args);
$profiler = PhutilServiceProfiler::getInstance();
$call_id = $profiler->beginServiceCall(array('type' => 'exec', 'subtype' => 'passthru', 'command' => $command));
$pipes = array();
$proc = proc_open($command, array(STDIN, STDOUT, STDERR), $pipes);
$err = proc_close($proc);
$profiler->endServiceCall($call_id, array('err' => $err));
return $err;
}
示例9: __construct
public final function __construct(array $argv)
{
declare (ticks=1);
$this->argv = $argv;
if (!self::$sighandlerInstalled) {
self::$sighandlerInstalled = true;
pcntl_signal(SIGINT, __CLASS__ . '::exitOnSignal');
pcntl_signal(SIGTERM, __CLASS__ . '::exitOnSignal');
}
// Without discard mode, this consumes unbounded amounts of memory. Keep
// memory bounded.
PhutilServiceProfiler::getInstance()->enableDiscardMode();
}
示例10: execute
public function execute()
{
$profiler = PhutilServiceProfiler::getInstance();
$call_id = $profiler->beginServiceCall(array('type' => 'conduit', 'method' => $this->method));
try {
$result = $this->executeMethod();
} catch (Exception $ex) {
$profiler->endServiceCall($call_id, array());
throw $ex;
}
$profiler->endServiceCall($call_id, array());
return $result;
}
示例11: initializeScriptEnvironment
public static function initializeScriptEnvironment()
{
self::initializeCommonEnvironment();
// NOTE: This is dangerous in general, but we know we're in a script context
// and are not vulnerable to CSRF.
AphrontWriteGuard::allowDangerousUnguardedWrites(true);
// There are several places where we log information (about errors, events,
// service calls, etc.) for analysis via DarkConsole or similar. These are
// useful for web requests, but grow unboundedly in long-running scripts and
// daemons. Discard data as it arrives in these cases.
PhutilServiceProfiler::getInstance()->enableDiscardMode();
DarkConsoleErrorLogPluginAPI::enableDiscardMode();
DarkConsoleEventPluginAPI::enableDiscardMode();
}
示例12: doCacheTest
private function doCacheTest(PhutilKeyValueCache $cache)
{
$key1 = 'test:' . mt_rand();
$key2 = 'test:' . mt_rand();
$default = 'cache-miss';
$value1 = 'cache-hit1';
$value2 = 'cache-hit2';
$cache->setProfiler(PhutilServiceProfiler::getInstance());
$test_info = get_class($cache);
// Test that we miss correctly on missing values.
$this->assertEqual($default, $cache->getKey($key1, $default), $test_info);
$this->assertEqual(array(), $cache->getKeys(array($key1, $key2)), $test_info);
// Test that we can set individual keys.
$cache->setKey($key1, $value1);
$this->assertEqual($value1, $cache->getKey($key1, $default), $test_info);
$this->assertEqual(array($key1 => $value1), $cache->getKeys(array($key1, $key2)), $test_info);
// Test that we can delete individual keys.
$cache->deleteKey($key1);
$this->assertEqual($default, $cache->getKey($key1, $default), $test_info);
$this->assertEqual(array(), $cache->getKeys(array($key1, $key2)), $test_info);
// Test that we can set multiple keys.
$cache->setKeys(array($key1 => $value1, $key2 => $value2));
$this->assertEqual($value1, $cache->getKey($key1, $default), $test_info);
$this->assertEqual(array($key1 => $value1, $key2 => $value2), $cache->getKeys(array($key1, $key2)), $test_info);
// Test that we can delete multiple keys.
$cache->deleteKeys(array($key1, $key2));
$this->assertEqual($default, $cache->getKey($key1, $default), $test_info);
$this->assertEqual(array(), $cache->getKeys(array($key1, $key2)), $test_info);
// NOTE: The TTL tests are necessarily slow (we must sleep() through the
// TTLs) and do not work with APC (it does not TTL until the next request)
// so they're disabled by default. If you're developing the cache stack,
// it may be useful to run them.
return;
// Test that keys expire when they TTL.
$cache->setKey($key1, $value1, 1);
$cache->setKey($key2, $value2, 5);
$this->assertEqual($value1, $cache->getKey($key1, $default));
$this->assertEqual($value2, $cache->getKey($key2, $default));
sleep(2);
$this->assertEqual($default, $cache->getKey($key1, $default));
$this->assertEqual($value2, $cache->getKey($key2, $default));
// Test that setting a 0 TTL overwrites a nonzero TTL.
$cache->setKey($key1, $value1, 1);
$this->assertEqual($value1, $cache->getKey($key1, $default));
$cache->setKey($key1, $value1, 0);
$this->assertEqual($value1, $cache->getKey($key1, $default));
sleep(2);
$this->assertEqual($value1, $cache->getKey($key1, $default));
}
示例13: __construct
public final function __construct(array $argv)
{
$this->argv = $argv;
$router = PhutilSignalRouter::getRouter();
$handler_key = 'daemon.term';
if (!$router->getHandler($handler_key)) {
$handler = new PhutilCallbackSignalHandler(SIGTERM, __CLASS__ . '::onTermSignal');
$router->installHandler($handler_key, $handler);
}
pcntl_signal(SIGINT, array($this, 'onGracefulSignal'));
pcntl_signal(SIGUSR2, array($this, 'onNotifySignal'));
// Without discard mode, this consumes unbounded amounts of memory. Keep
// memory bounded.
PhutilServiceProfiler::getInstance()->enableDiscardMode();
$this->beginStdoutCapture();
}
示例14: processRequest
public function processRequest()
{
$request = $this->getRequest();
$user = $request->getUser();
$cache = new PhabricatorKeyValueDatabaseCache();
$cache = new PhutilKeyValueCacheProfiler($cache);
$cache->setProfiler(PhutilServiceProfiler::getInstance());
$result = $cache->getKey('darkconsole:' . $this->key);
if (!$result) {
return new Aphront400Response();
}
try {
$result = phutil_json_decode($result);
} catch (PhutilJSONParserException $ex) {
return new Aphront400Response();
}
if ($result['vers'] != DarkConsoleCore::STORAGE_VERSION) {
return new Aphront400Response();
}
if ($result['user'] != $user->getPHID()) {
return new Aphront400Response();
}
$output = array();
$output['tabs'] = $result['tabs'];
$output['panel'] = array();
foreach ($result['data'] as $class => $data) {
try {
$obj = newv($class, array());
$obj->setData($data);
$obj->setRequest($request);
$panel = $obj->renderPanel();
// Because cookie names can now be prefixed, wipe out any cookie value
// with the session cookie name anywhere in its name.
$pattern = '(' . preg_quote(PhabricatorCookies::COOKIE_SESSION) . ')';
foreach ($_COOKIE as $cookie_name => $cookie_value) {
if (preg_match($pattern, $cookie_name)) {
$panel = PhutilSafeHTML::applyFunction('str_replace', $cookie_value, '(session-key)', $panel);
}
}
$output['panel'][$class] = $panel;
} catch (Exception $ex) {
$output['panel'][$class] = 'error';
}
}
return id(new AphrontAjaxResponse())->setContent($output);
}
示例15: getKey
public function getKey(AphrontRequest $request)
{
$plugins = $this->getPlugins();
foreach ($plugins as $plugin) {
$plugin->setRequest($request);
$plugin->willShutdown();
}
foreach ($plugins as $plugin) {
$plugin->didShutdown();
}
foreach ($plugins as $plugin) {
$plugin->setData($plugin->generateData());
}
$plugins = msort($plugins, 'getOrderKey');
$key = Filesystem::readRandomCharacters(24);
$tabs = array();
$data = array();
foreach ($plugins as $plugin) {
$class = get_class($plugin);
$tabs[] = array('class' => $class, 'name' => $plugin->getName(), 'color' => $plugin->getColor());
$data[$class] = $this->sanitizeForJSON($plugin->getData());
}
$storage = array('vers' => self::STORAGE_VERSION, 'tabs' => $tabs, 'data' => $data, 'user' => $request->getUser() ? $request->getUser()->getPHID() : null);
$cache = new PhabricatorKeyValueDatabaseCache();
$cache = new PhutilKeyValueCacheProfiler($cache);
$cache->setProfiler(PhutilServiceProfiler::getInstance());
// This encoding may fail if there are, e.g., database queries which
// include binary data. It would be a little cleaner to try to strip these,
// but just do something non-broken here if we end up with unrepresentable
// data.
$json = @json_encode($storage);
if (!$json) {
$json = '{}';
}
$cache->setKeys(array('darkconsole:' . $key => $json), $ttl = 60 * 60 * 6);
return $key;
}