• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP PhutilServiceProfiler类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中PhutilServiceProfiler的典型用法代码示例。如果您正苦于以下问题:PHP PhutilServiceProfiler类的具体用法?PHP PhutilServiceProfiler怎么用?PHP PhutilServiceProfiler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了PhutilServiceProfiler类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: 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;
 }
开发者ID:lsubra,项目名称:libphutil,代码行数:26,代码来源:ConduitFuture.php


示例2: 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;
 }
开发者ID:barcelonascience,项目名称:libphutil,代码行数:40,代码来源:PhutilExecPassthru.php


示例3: 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;
 }
开发者ID:barcelonascience,项目名称:libphutil,代码行数:28,代码来源:ConduitFuture.php


示例4: 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;
}
开发者ID:chaozhang80,项目名称:tool-package,代码行数:35,代码来源:execx.php


示例5: getInstance

 public static function getInstance()
 {
     if (empty(self::$instance)) {
         self::$instance = new PhutilServiceProfiler();
     }
     return self::$instance;
 }
开发者ID:piccoloman,项目名称:libphutil,代码行数:7,代码来源:PhutilServiceProfiler.php


示例6: 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());
 }
开发者ID:chaozhang80,项目名称:tool-package,代码行数:28,代码来源:PhutilEventEngine.php


示例7: 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());
 }
开发者ID:denghp,项目名称:phabricator,代码行数:12,代码来源:PhabricatorS3FileStorageEngine.php


示例8: 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());
 }
开发者ID:truSense,项目名称:phabricator,代码行数:12,代码来源:PhabricatorS3FileStorageEngine.php


示例9: 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;
}
开发者ID:rmoorman,项目名称:libphutil,代码行数:22,代码来源:execx.php


示例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;
 }
开发者ID:NeoArmageddon,项目名称:phabricator,代码行数:13,代码来源:ConduitCall.php


示例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();
 }
开发者ID:JohnnyEstilles,项目名称:phabricator,代码行数:14,代码来源:PhabricatorEnv.php


示例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));
 }
开发者ID:relrod,项目名称:libphutil,代码行数:49,代码来源:PhutilKeyValueCacheTestCase.php


示例13: 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);
 }
开发者ID:pugong,项目名称:phabricator,代码行数:46,代码来源:DarkConsoleDataController.php


示例14: 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;
 }
开发者ID:pugong,项目名称:phabricator,代码行数:37,代码来源:DarkConsoleCore.php


示例15: phutil_console_wrap

}
echo phutil_console_wrap(phutil_console_format('This script will test that you have configured valid credentials for ' . 'access to a repository, so the Phabricator daemons can pull from it. ' . 'You should run this as the **same user you will run the daemons as**, ' . 'from the **same machine they will run from**. Doing this will help ' . 'detect various problems with your configuration, such as SSH issues.'));
list($whoami) = execx('whoami');
$whoami = trim($whoami);
$ok = phutil_console_confirm("Do you want to continue as '{$whoami}'?");
if (!$ok) {
    die(1);
}
$callsign = $argv[1];
echo "Loading '{$callsign}' repository...\n";
$repository = id(new PhabricatorRepository())->loadOneWhere('callsign = %s', $argv[1]);
if (!$repository) {
    throw new Exception("No such repository exists!");
}
$vcs = $repository->getVersionControlSystem();
PhutilServiceProfiler::installEchoListener();
echo "Trying to connect to the remote...\n";
switch ($vcs) {
    case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
        $err = $repository->passthruRemoteCommand('--limit 1 log %s', $repository->getRemoteURI());
        break;
    case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
        // Do an ls-remote on a nonexistent ref, which we expect to just return
        // nothing.
        $err = $repository->passthruRemoteCommand('ls-remote %s %s', $repository->getRemoteURI(), 'just-testing');
        break;
    default:
        throw new Exception("Unsupported repository type.");
}
if ($err) {
    echo phutil_console_format("<bg:red>** FAIL **</bg> Connection failed. The credentials for this " . "repository appear to be incorrectly configured.\n");
开发者ID:hwang36,项目名称:phabricator,代码行数:31,代码来源:test_connection.php


示例16: __construct

    public function __construct(array $argv)
    {
        PhutilServiceProfiler::getInstance()->enableDiscardMode();
        $original_argv = $argv;
        $args = new PhutilArgumentParser($argv);
        $args->setTagline('daemon overseer');
        $args->setSynopsis(<<<EOHELP
**launch_daemon.php** [__options__] __daemon__
    Launch and oversee an instance of __daemon__.
EOHELP
);
        $args->parseStandardArguments();
        $args->parsePartial(array(array('name' => 'trace-memory', 'help' => 'Enable debug memory tracing.'), array('name' => 'log', 'param' => 'file', 'help' => 'Send output to __file__.'), array('name' => 'daemonize', 'help' => 'Run in the background.'), array('name' => 'phd', 'param' => 'dir', 'help' => 'Write PID information to __dir__.'), array('name' => 'verbose', 'help' => 'Enable verbose activity logging.'), array('name' => 'load-phutil-library', 'param' => 'library', 'repeat' => true, 'help' => 'Load __library__.')));
        $argv = array();
        $more = $args->getUnconsumedArgumentVector();
        $this->daemon = array_shift($more);
        if (!$this->daemon) {
            $args->printHelpAndExit();
        }
        if ($args->getArg('trace')) {
            $this->traceMode = true;
            $argv[] = '--trace';
        }
        if ($args->getArg('trace-memory')) {
            $this->traceMode = true;
            $this->traceMemory = true;
            $argv[] = '--trace-memory';
        }
        if ($args->getArg('load-phutil-library')) {
            foreach ($args->getArg('load-phutil-library') as $library) {
                $argv[] = '--load-phutil-library=' . $library;
            }
        }
        $log = $args->getArg('log');
        if ($log) {
            ini_set('error_log', $log);
            $argv[] = '--log=' . $log;
        }
        $verbose = $args->getArg('verbose');
        if ($verbose) {
            $this->verbose = true;
            $argv[] = '--verbose';
        }
        $this->daemonize = $args->getArg('daemonize');
        $this->phddir = $args->getArg('phd');
        $this->argv = $argv;
        $this->moreArgs = coalesce($more, array());
        error_log("Bringing daemon '{$this->daemon}' online...");
        if (self::$instance) {
            throw new Exception('You may not instantiate more than one Overseer per process.');
        }
        self::$instance = $this;
        if ($this->daemonize) {
            // We need to get rid of these or the daemon will hang when we TERM it
            // waiting for something to read the buffers. TODO: Learn how unix works.
            fclose(STDOUT);
            fclose(STDERR);
            ob_start();
            $pid = pcntl_fork();
            if ($pid === -1) {
                throw new Exception('Unable to fork!');
            } else {
                if ($pid) {
                    exit(0);
                }
            }
        }
        if ($this->phddir) {
            $desc = array('name' => $this->daemon, 'argv' => $this->moreArgs, 'pid' => getmypid(), 'start' => time());
            Filesystem::writeFile($this->phddir . '/daemon.' . getmypid(), json_encode($desc));
        }
        $this->daemonID = $this->generateDaemonID();
        $this->dispatchEvent(self::EVENT_DID_LAUNCH, array('argv' => array_slice($original_argv, 1), 'explicitArgv' => $this->moreArgs));
        declare (ticks=1);
        pcntl_signal(SIGUSR1, array($this, 'didReceiveKeepaliveSignal'));
        pcntl_signal(SIGUSR2, array($this, 'didReceiveNotifySignal'));
        pcntl_signal(SIGINT, array($this, 'didReceiveGracefulSignal'));
        pcntl_signal(SIGTERM, array($this, 'didReceiveTerminalSignal'));
    }
开发者ID:lsubra,项目名称:libphutil,代码行数:79,代码来源:PhutilDaemonOverseer.php


示例17: __construct

    public function __construct(array $argv)
    {
        PhutilServiceProfiler::getInstance()->enableDiscardMode();
        $args = new PhutilArgumentParser($argv);
        $args->setTagline(pht('daemon overseer'));
        $args->setSynopsis(<<<EOHELP
**launch_daemon.php** [__options__] __daemon__
    Launch and oversee an instance of __daemon__.
EOHELP
);
        $args->parseStandardArguments();
        $args->parse(array(array('name' => 'trace-memory', 'help' => pht('Enable debug memory tracing.')), array('name' => 'verbose', 'help' => pht('Enable verbose activity logging.')), array('name' => 'label', 'short' => 'l', 'param' => 'label', 'help' => pht('Optional process label. Makes "%s" nicer, no behavioral effects.', 'ps'))));
        $argv = array();
        if ($args->getArg('trace')) {
            $this->traceMode = true;
            $argv[] = '--trace';
        }
        if ($args->getArg('trace-memory')) {
            $this->traceMode = true;
            $this->traceMemory = true;
            $argv[] = '--trace-memory';
        }
        $verbose = $args->getArg('verbose');
        if ($verbose) {
            $this->verbose = true;
            $argv[] = '--verbose';
        }
        $label = $args->getArg('label');
        if ($label) {
            $argv[] = '-l';
            $argv[] = $label;
        }
        $this->argv = $argv;
        if (function_exists('posix_isatty') && posix_isatty(STDIN)) {
            fprintf(STDERR, pht('Reading daemon configuration from stdin...') . "\n");
        }
        $config = @file_get_contents('php://stdin');
        $config = id(new PhutilJSONParser())->parse($config);
        $this->libraries = idx($config, 'load');
        $this->log = idx($config, 'log');
        $this->daemonize = idx($config, 'daemonize');
        $this->piddir = idx($config, 'piddir');
        $this->config = $config;
        if (self::$instance) {
            throw new Exception(pht('You may not instantiate more than one Overseer per process.'));
        }
        self::$instance = $this;
        $this->startEpoch = time();
        // Check this before we daemonize, since if it's an issue the child will
        // exit immediately.
        if ($this->piddir) {
            $dir = $this->piddir;
            try {
                Filesystem::assertWritable($dir);
            } catch (Exception $ex) {
                throw new Exception(pht("Specified daemon PID directory ('%s') does not exist or is " . "not writable by the daemon user!", $dir));
            }
        }
        if (!idx($config, 'daemons')) {
            throw new PhutilArgumentUsageException(pht('You must specify at least one daemon to start!'));
        }
        if ($this->log) {
            // NOTE: Now that we're committed to daemonizing, redirect the error
            // log if we have a `--log` parameter. Do this at the last moment
            // so as many setup issues as possible are surfaced.
            ini_set('error_log', $this->log);
        }
        if ($this->daemonize) {
            // We need to get rid of these or the daemon will hang when we TERM it
            // waiting for something to read the buffers. TODO: Learn how unix works.
            fclose(STDOUT);
            fclose(STDERR);
            ob_start();
            $pid = pcntl_fork();
            if ($pid === -1) {
                throw new Exception(pht('Unable to fork!'));
            } else {
                if ($pid) {
                    exit(0);
                }
            }
        }
        $this->modules = PhutilDaemonOverseerModule::getAllModules();
        pcntl_signal(SIGUSR2, array($this, 'didReceiveNotifySignal'));
        pcntl_signal(SIGHUP, array($this, 'didReceiveReloadSignal'));
        pcntl_signal(SIGINT, array($this, 'didReceiveGracefulSignal'));
        pcntl_signal(SIGTERM, array($this, 'didReceiveTerminalSignal'));
    }
开发者ID:endlessm,项目名称:libphutil,代码行数:88,代码来源:PhutilDaemonOverseer.php


示例18: closeProcess

 /**
  * Close and free resources if necessary.
  *
  * @return void
  * @task internal
  */
 private function closeProcess()
 {
     foreach ($this->pipes as $pipe) {
         if (isset($pipe)) {
             @fclose($pipe);
         }
     }
     $this->pipes = array(null, null, null);
     if ($this->proc) {
         @proc_close($this->proc);
         $this->proc = null;
     }
     $this->stdin = null;
     if ($this->profilerCallID !== null) {
         $profiler = PhutilServiceProfiler::getInstance();
         $profiler->endServiceCall($this->profilerCallID, array('err' => $this->result ? idx($this->result, 0) : null));
         $this->profilerCallID = null;
     }
 }
开发者ID:WilkGardariki,项目名称:libphutil,代码行数:25,代码来源:ExecFuture.php


示例19: __construct

 public function __construct($cache_directory, $name)
 {
     $dir_cache = id(new PhutilDirectoryKeyValueCache())->setCacheDirectory($cache_directory);
     $profiled_cache = id(new PhutilKeyValueCacheProfiler($dir_cache))->setProfiler(PhutilServiceProfiler::getInstance())->setName($name);
     $this->cache = $profiled_cache;
 }
开发者ID:pugong,项目名称:phabricator,代码行数:6,代码来源:DivinerDiskCache.php


示例20: isReady

 public function isReady()
 {
     if (isset($this->result)) {
         return true;
     }
     $uri = $this->getURI();
     $domain = id(new PhutilURI($uri))->getDomain();
     if (!$this->handle) {
         $uri_object = new PhutilURI($uri);
         $proxy = PhutilHTTPEngineExtension::buildHTTPProxyURI($uri_object);
         $profiler = PhutilServiceProfiler::getInstance();
         $this->profilerCallID = $profiler->beginServiceCall(array('type' => 'http', 'uri' => $uri, 'proxy' => (string) $proxy));
         if (!self::$multi) {
             self::$multi = curl_multi_init();
             if (!self::$multi) {
                 throw new Exception(pht('%s failed!', 'curl_multi_init()'));
             }
         }
         if (!empty(self::$pool[$domain])) {
             $curl = array_pop(self::$pool[$domain]);
         } else {
             $curl = curl_init();
             if (!$curl) {
                 throw new Exception(pht('%s failed!', 'curl_init()'));
             }
         }
         $this->handle = $curl;
         curl_multi_add_handle(self::$multi, $curl);
         curl_setopt($curl, CURLOPT_URL, $uri);
         if (defined('CURLOPT_PROTOCOLS')) {
             // cURL supports a lot of protocols, and by default it will honor
             // redirects across protocols (for instance, from HTTP to POP3). Beyond
             // being very silly, this also has security implications:
             //
             //   http://blog.volema.com/curl-rce.html
             //
             // Disable all protocols other than HTTP and HTTPS.
             $allowed_protocols = CURLPROTO_HTTPS | CURLPROTO_HTTP;
             curl_setopt($curl, CURLOPT_PROTOCOLS, $allowed_protocols);
             curl_setopt($curl, CURLOPT_REDIR_PROTOCOLS, $allowed_protocols);
         }
         if (strlen($this->rawBody)) {
             if ($this->getData()) {
                 throw new Exception(pht('You can not execute an HTTP future with both a raw request ' . 'body and structured request data.'));
             }
             // We aren't actually going to use this file handle, since we are
             // just pushing data through the callback, but cURL gets upset if
             // we don't hand it a real file handle.
             $tmp = new TempFile();
             $this->fileHandle = fopen($tmp, 'r');
             // NOTE: We must set CURLOPT_PUT here to make cURL use CURLOPT_INFILE.
             // We'll possibly overwrite the method later on, unless this is really
             // a PUT request.
             curl_setopt($curl, CURLOPT_PUT, true);
             curl_setopt($curl, CURLOPT_INFILE, $this->fileHandle);
             curl_setopt($curl, CURLOPT_INFILESIZE, strlen($this->rawBody));
             curl_setopt($curl, CURLOPT_READFUNCTION, array($this, 'willWriteBody'));
         } else {
             $data = $this->formatRequestDataForCURL();
             curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
         }
         $headers = $this->getHeaders();
         $saw_expect = false;
         for ($ii = 0; $ii < count($headers); $ii++) {
             list($name, $value) = $headers[$ii];
             $headers[$ii] = $name . ': ' . $value;
             if (!strncasecmp($name, 'Expect', strlen('Expect'))) {
                 $saw_expect = true;
             }
         }
         if (!$saw_expect) {
             // cURL sends an "Expect" header by default for certain requests. While
             // there is some reasoning behind this, it causes a practical problem
             // in that lighttpd servers reject these requests with a 417. Both sides
             // are locked in an eternal struggle (lighttpd has introduced a
             // 'server.reject-expect-100-with-417' option to deal with this case).
             //
             // The ostensibly correct way to suppress this behavior on the cURL side
             // is to add an empty "Expect:" header. If we haven't seen some other
             // explicit "Expect:" header, do so.
             //
             // See here, for example, although this issue is fairly widespread:
             //   http://curl.haxx.se/mail/archive-2009-07/0008.html
             $headers[] = 'Expect:';
         }
         curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
         // Set the requested HTTP method, e.g. GET / POST / PUT.
         curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $this->getMethod());
         // Make sure we get the headers and data back.
         curl_setopt($curl, CURLOPT_HEADER, true);
         curl_setopt($curl, CURLOPT_WRITEFUNCTION, array($this, 'didReceiveDataCallback'));
         if ($this->followLocation) {
             curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
             curl_setopt($curl, CURLOPT_MAXREDIRS, 20);
         }
         if (defined('CURLOPT_TIMEOUT_MS')) {
             // If CURLOPT_TIMEOUT_MS is available, use the higher-precision timeout.
             $timeout = max(1, ceil(1000 * $this->getTimeout()));
             curl_setopt($curl, CURLOPT_TIMEOUT_MS, $timeout);
         } else {
//.........这里部分代码省略.........
开发者ID:endlessm,项目名称:libphutil,代码行数:101,代码来源:HTTPSFuture.php



注:本文中的PhutilServiceProfiler类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP PhutilTypeSpec类代码示例发布时间:2022-05-23
下一篇:
PHP PhutilEventEngine类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap