本文整理汇总了PHP中php_sapi_name函数的典型用法代码示例。如果您正苦于以下问题:PHP php_sapi_name函数的具体用法?PHP php_sapi_name怎么用?PHP php_sapi_name使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了php_sapi_name函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Making the class non-abstract with a protected constructor does a better
* job of preventing instantiation than just marking the class as abstract.
*
* @see start()
*/
public function __construct(array $configs)
{
// Quickly initialize some defaults like usePEAR
// by adding the $premature flag
$this->_optionsInit(true);
$this->setOptions($configs);
if ($this->opt('logPhpErrors')) {
set_error_handler(array('self', 'phpErrors'), E_ALL);
}
// Check the PHP configuration
if (!defined('SIGHUP')) {
trigger_error('PHP is compiled without --enable-pcntl directive', E_USER_ERROR);
}
// Check for CLI
if (php_sapi_name() !== 'cli') {
trigger_error('You can only create daemon from the command line (CLI-mode)', E_USER_ERROR);
}
// Check for POSIX
if (!function_exists('posix_getpid')) {
trigger_error('PHP is compiled without --enable-posix directive', E_USER_ERROR);
}
// Enable Garbage Collector (PHP >= 5.3)
if (function_exists('gc_enable')) {
gc_enable();
}
// Initialize & check variables
if (false === $this->_optionsInit(false)) {
if (is_object($this->_option) && is_array($this->_option->errors)) {
foreach ($this->_option->errors as $error) {
$this->notice($error);
}
}
trigger_error('Crucial options are not set. Review log:', E_USER_ERROR);
}
}
示例2: index
public function index()
{
$os = explode(' ', php_uname());
$mysql_support = function_exists('mysql_close') ? '<font color="green">√</font>' : '<font color="red">×</font>';
$register_globals = get_cfg_var("register_globals") ? '<font color="green">√</font>' : '<font color="red">×</font>';
$enable_dl = get_cfg_var("enable_dl") ? '<font color="green">√</font>' : '<font color="red">×</font>';
$allow_url_fopen = get_cfg_var("allow_url_fopen") ? '<font color="green">√</font>' : '<font color="red">×</font>';
$display_errors = get_cfg_var("display_errors") ? '<font color="green">√</font>' : '<font color="red">×</font>';
$session_support = function_exists('session_start') ? '<font color="green">√</font>' : '<font color="red">×</font>';
$config['server_name'] = $_SERVER['SERVER_NAME'];
$config['server_ip'] = @gethostbyname($_SERVER['SERVER_NAME']);
$config['server_time'] = date("Y年n月j日 H:i:s");
$config['os'] = $os[0];
$config['os_core'] = $os[2];
$config['server_root'] = dirname(dirname($_SERVER['SCRIPT_FILENAME']));
$config['server_engine'] = $_SERVER['SERVER_SOFTWARE'];
$config['server_port'] = $_SERVER['SERVER_PORT'];
$config['php_version'] = PHP_VERSION;
$config['php_run_type'] = strtoupper(php_sapi_name());
$config['mysql_support'] = $mysql_support;
$config['register_globals'] = $register_globals;
$config['allow_url_fopen'] = $allow_url_fopen;
$config['display_errors'] = $display_errors;
$config['enable_dl'] = $enable_dl;
$config['memory_limit'] = get_cfg_var("memory_limit");
$config['post_max_size'] = get_cfg_var("post_max_size");
$config['upload_max_filesize'] = get_cfg_var("upload_max_filesize");
$config['max_execution_time'] = get_cfg_var("max_execution_time");
$config['session_support'] = $session_support;
$this->config_arr = $config;
$this->display();
}
示例3: upgrade
public function upgrade()
{
if (php_sapi_name() == "cli") {
// @todo this may screw up some module installers, but we don't have a better answer at
// this time.
$_SERVER["HTTP_HOST"] = "example.com";
} else {
if (!user::active()->admin && !Session::instance()->get("can_upgrade", false)) {
access::forbidden();
}
}
// Upgrade gallery and user first
module::install("gallery");
module::install("user");
// Then upgrade the rest
foreach (module::available() as $id => $module) {
if ($id == "gallery") {
continue;
}
if ($module->active && $module->code_version != $module->version) {
module::install($id);
}
}
if (php_sapi_name() == "cli") {
print "Upgrade complete\n";
} else {
url::redirect("upgrader?done=1");
}
}
示例4: run
public function run()
{
if (fnmatch('*cli*', php_sapi_name())) {
$dir = Config::get('dir.schedules', APPLICATION_PATH . DS . 'schedules');
if (is_dir($dir)) {
Timer::start();
Cli::show("Start of execution", 'COMMENT');
$files = glob($dir . DS . '*.php');
foreach ($files as $file) {
require_once $file;
$object = str_replace('.php', '', Arrays::last(explode(DS, $file)));
$class = 'Thin\\' . ucfirst(Inflector::camelize($object . '_schedule'));
$instance = lib('app')->make($class);
$methods = get_class_methods($instance);
Cli::show("Start schedule '{$object}'", 'COMMENT');
foreach ($methods as $method) {
$when = $this->getWhen($instance, $method);
$isDue = $this->isDue($object, $method, $when);
if (true === $isDue) {
Cli::show("Execution of {$object}->{$method}", 'INFO');
$instance->{$method}();
} else {
Cli::show("No need to execute {$object}->{$method}", 'QUESTION');
}
}
}
Cli::show("Time of execution [" . Timer::get() . " s.]", 'SUCCESS');
Cli::show("end of execution", 'COMMENT');
}
}
}
示例5: ic_system_info
function ic_system_info()
{
$thread_safe = false;
$debug_build = false;
$cgi_cli = false;
$php_ini_path = '';
ob_start();
phpinfo(INFO_GENERAL);
$php_info = ob_get_contents();
ob_end_clean();
foreach (split("\n", $php_info) as $line) {
if (eregi('command', $line)) {
continue;
}
if (eregi('thread safety.*(enabled|yes)', $line)) {
$thread_safe = true;
}
if (eregi('debug.*(enabled|yes)', $line)) {
$debug_build = true;
}
if (eregi("configuration file.*(</B></td><TD ALIGN=\"left\">| => |v\">)([^ <]*)(.*</td.*)?", $line, $match)) {
$php_ini_path = $match[2];
if (!@file_exists($php_ini_path)) {
$php_ini_path = '';
}
}
$cgi_cli = strpos(php_sapi_name(), 'cgi') !== false || strpos(php_sapi_name(), 'cli') !== false;
}
return array('THREAD_SAFE' => $thread_safe, 'DEBUG_BUILD' => $debug_build, 'PHP_INI' => $php_ini_path, 'CGI_CLI' => $cgi_cli);
}
示例6: scanInput
/**
* Scan the input for XXE attacks.
*
* @param string $input
* Unsafe input
* @param Closure $callback
* Callback called to build the dom.
* Must be an instance of DomDocument and receives the input as argument
*
* @return bool|DomDocument False if an XXE attack was discovered,
* otherwise the return of the callback
*/
private static function scanInput($input, Closure $callback)
{
$isRunningFpm = substr(php_sapi_name(), 0, 3) === 'fpm';
if ($isRunningFpm) {
// If running with PHP-FPM and an entity is detected we refuse to parse the feed
// @see https://bugs.php.net/bug.php?id=64938
if (strpos($input, '<!ENTITY') !== false) {
return false;
}
} else {
$entityLoaderDisabled = libxml_disable_entity_loader(true);
}
libxml_use_internal_errors(true);
$dom = $callback($input);
// Scan for potential XEE attacks using ENTITY
foreach ($dom->childNodes as $child) {
if ($child->nodeType === XML_DOCUMENT_TYPE_NODE) {
if ($child->entities->length > 0) {
return false;
}
}
}
if ($isRunningFpm === false) {
libxml_disable_entity_loader($entityLoaderDisabled);
}
return $dom;
}
示例7: register
/**
* Automatically registers all service classes in $this->services array
* {@inheritdoc}
* @param Application|\Apitude\Core\Application $app
*/
public function register(Application $app)
{
foreach ($this->services as $key => $class) {
if (is_numeric($key)) {
$key = $class;
}
$app[$key] = $app->share(function () use($class, $app) {
$result = new $class();
$app->initialize($result);
return $result;
});
}
if (!empty($this->doctrineEventSubscribers)) {
$config = $app['config'];
foreach ($this->doctrineEventSubscribers as $class) {
$config['orm.subscribers'][] = $class;
}
}
if (!empty($this->entityFolders)) {
if (!isset($config)) {
$config = $app['config'];
}
foreach ($this->entityFolders as $namespace => $path) {
$config['orm.options']['orm.em.options']['mappings'][] = ['type' => 'annotation', 'namespace' => $namespace, 'path' => $path, 'use_simple_annotation_reader' => false];
}
}
if (isset($config)) {
$app['config'] = $config;
}
if (php_sapi_name() === 'cli' && !empty($this->commands)) {
$app['base_commands'] = $app->extend('base_commands', function (array $commands) {
return array_merge($commands, $this->commands);
});
}
}
示例8: dump
/**
* Dump specified value.
*
* @param mixed $value
* @param int $output
* @return null|string
*/
public function dump($value, $output = self::OUTPUT_ECHO)
{
if (php_sapi_name() === 'cli' && $output == self::OUTPUT_ECHO) {
print_r($value);
if (is_scalar($value)) {
echo "\n";
}
return null;
}
//Dumping is pretty slow operation, let's record it so we can exclude dump time from application
//timeline
$benchmark = $this->benchmark('dump');
try {
switch ($output) {
case self::OUTPUT_ECHO:
echo $this->style->mountContainer($this->dumpValue($value, '', 0));
break;
case self::OUTPUT_RETURN:
return $this->style->mountContainer($this->dumpValue($value, '', 0));
break;
case self::OUTPUT_LOG:
$this->logger()->debug(print_r($value, true));
break;
case self::OUTPUT_LOG_NICE:
$this->logger()->debug($this->dump($value, self::OUTPUT_RETURN));
break;
}
return null;
} finally {
$this->benchmark($benchmark);
}
}
示例9: __construct
/**
* 构造函数
* @param mixed $arg 对象参数, 常为 SQL 语句或要导入的文件路径
*/
public function __construct($type, $arg)
{
$this->type = $type;
$this->arg = $arg;
$this->inCli = php_sapi_name() === 'cli';
$this->init();
}
示例10: _prepare
/**
* (non-PHPdoc)
* @see \parallely\AbstractTransport::_prepare()
*/
protected function _prepare()
{
if (extension_loaded('xcache') !== true or php_sapi_name() === 'cli') {
throw new \parallely\Exception(\parallely\Exception::SETUP_ERROR);
}
return $this;
}
示例11: run
public function run()
{
// Initialize router
try {
if (php_sapi_name() == 'cli') {
// Handle console apps
// @todo: finish!
$router = new Router($this->getProjectFromArgs());
} else {
// Handle web apps
$url = UrlFactory::autodetect();
$router = new Router($this->getProjectFromUrl($url));
$router->parseUrl($url);
}
} catch (RouteNotFoundException $e) {
$context = new Context($e->getProject(), $e->getUrl());
if ($this->onRouteNotFound) {
// Call the user defined route not found handler
call_user_func($this->onRouteNotFound, ['statusCode' => 404, 'context' => $context, 'exceptionMessage' => $e->getMessage()]);
} else {
// Display a default error page
$response = new Phtml($context);
$response->setStatusCode(404)->setViewDir(__DIR__ . '/Scripts')->setViewFilename('error.phtml')->setViewParams(['statusCode' => 404, 'exceptionMessage' => $e->getMessage()])->render();
}
}
}
示例12: run
public function run()
{
static::$netteDirectory = realpath(__DIR__ . '/../../../../app');
$netteContainer = $this->getNetteContainer();
if (php_sapi_name() !== 'cli') {
define('STDIN', fopen('php://stdin', 'r'));
echo '<pre>';
}
CLI::write('Welcome to the Nette Framework CRUD generator 1.0@beta5.', 0, FALSE);
static::$settings = (object) ['netteRoot' => realpath(static::$netteDirectory . '/..'), 'netteConfig' => FALSE, 'netteDatabase' => FALSE, 'source' => \Utils\Constants::SOURCE_MYSQL_DISCOVERED, 'tables' => [], 'table' => FALSE, 'target' => \Utils\Constants::TARGET_NETTE_DATABASE, 'foreignKeys' => \Utils\Constants::FOREIGN_KEYS_TABLE, 'module' => FALSE, 'template' => realpath(__DIR__ . '/Templates/default'), 'php' => '<?php', 'entityManager' => NULL];
$this->showSourceDialog();
CLI::write('Verifying Nette configuration:', 0, TRUE, TRUE, TRUE);
static::$settings->netteDatabase = $this->getDatabaseConnectionParameters($netteContainer);
static::$settings->netteConfig = \Nette\Neon\Neon::decode(\Bruha\Generator\Utils\File::read(static::$netteDirectory . '/config/config.neon'));
if ($this->checkExtensionsConfiguration()) {
CLI::write('New extensions were installed.', 0, TRUE, TRUE, TRUE);
CLI::write('Application needs to be restarted for loading them.', 1);
CLI::write("Write 'php -f index.php' for start with new loaded extensions.", 2);
exit;
}
$this->showTablesDialog($this->processSourceDialog($netteContainer));
$this->showTargetDialog();
$this->showForeignKeysDialog();
$this->showModuleDialog();
$this->chooseTemplatesDialog();
static::$startTime = microtime(TRUE);
$this->generate();
}
示例13: isConsole
/**
* isConsole
*
* @return boolean
*/
public static function isConsole()
{
if (php_sapi_name() == 'cli') {
return true;
}
return false;
}
示例14: loadSecurity
private function loadSecurity()
{
if (php_sapi_name() != 'cli') {
$this->__security = new \PAJ\Library\Security\SecurityController();
$this->set('loggedin', $this->__security->get('loggedin'));
}
}
示例15: __construct
/**
* Class constructor
*
* @param array An optional associative array of configuration settings.
* Recognized key values include 'clientId' (this list is not meant to be comprehensive).
*/
public function __construct($config = array())
{
$config['clientId'] = 0;
\Event::listen(function ($event) {
// This must be done before the session is read, otherwise it will overwrite
// the existing session with a guest non-https session prior to redirecting to https
// NOTE: we're including a cli check here because the console currently uses the 'site'
// application. This should be remedied in the new framework.
$app = $event->getArgument('app');
if ($app->getCfg('force_ssl') == 2 && php_sapi_name() != 'cli') {
$uri = JURI::getInstance();
if (strtolower($uri->getScheme()) != 'https') {
// We also can't use the Application::redirect method here as
// it tries to use JFactory::getDocument, which doesn't work
// prior to application initialization
$uri->setScheme('https');
header('HTTP/1.1 303 See other');
header('Location: ' . (string) $uri);
header('Content-Type: text/html;');
$app->close();
}
}
}, 'application_onBeforeSessionCreate');
parent::__construct($config);
}