Commit dbe173d1 authored by tufengqi's avatar tufengqi

init

parents
<?php
class ConsoleInitAppHelper
{
static $realip;
private $configures = [];
/**
* 获取配置信息
* @param string $name 配置名
* @param string $file 配置文件
* @param mixed $default 配置默认值
* @return mixed
* @throws Exception
*/
public function getConfig($name = null, $file = "common", $default = null, $force_reload = false)
{
// 获取文件级别配置时,默认值必须为数组
if (!$name) {
if (is_null($default)) {
$default = [];
} elseif (!is_array($default)) {
throw new Exception('文件级别配置的默认值必须为数组');
}
}
// 获取当前文件级别配置
if (!isset($this->configures[$file]) || $force_reload) {
$config = $this->loadConfig($file);
$this->configures[$file] = $config;
} else {
$config = $this->configures[$file];
}
// 获取最终配置
if (!$name) {
$config = $config ? $config : $default;
} else {
$config = $config && isset($config[$name]) ? $config[$name] : $default;
}
return $config;
}
/**
* 导入配置文件
* @param string $file 配置文件名
*/
public function loadConfig($file = "common")
{
global $G_CONF_PATH;
$config = [];
foreach ($G_CONF_PATH as $path) {
$fullpath = "$path$file.php";
$exists = false;
if (!file_exists($fullpath)) {
continue;
}
include $fullpath;
}
if (!isset($config)) {
trigger_error("Variable \$config not found when load $file", E_USER_WARNING);
return false;
}
return $config;
}
public static function isOnlineHost()
{
return false;
}
/**
* 不同环境下获取真实的IP
*/
public static function getUserIp()
{
if (self::$realip) {
return self::$realip;
}
// 判断服务器是否允许$_SERVER
if (isset($_SERVER)) {
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$realip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
$realip = $_SERVER['HTTP_CLIENT_IP'];
} else {
$realip = $_SERVER['REMOTE_ADDR'];
}
} else {
// 不允许就使用getenv获取
if (getenv("HTTP_X_FORWARDED_FOR")) {
$realip = getenv("HTTP_X_FORWARDED_FOR");
} elseif (getenv("HTTP_CLIENT_IP")) {
$realip = getenv("HTTP_CLIENT_IP");
} else {
$realip = getenv("REMOTE_ADDR");
}
}
self::$realip = $realip;
return $realip;
}
public static function isInnerUserIp($user_ip, $company_ip_list)
{
if ((in_array($user_ip, $company_ip_list) ||
!filter_var($user_ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE) || '127.0.0.1' === $user_ip)) {
return true;
}
return false;
}
public static function isOuterUserIp($user_ip, $company_ip_list)
{
return !self::isInnerUserIp($user_ip, $company_ip_list);
}
public static function isFromCompanyAccessOuterHost()
{
return false;
}
/**
* 判断是否是真实的外部用户访问 真实外部用户
*/
public static function isRealOuterAccess()
{
return false;
}
}
\ No newline at end of file
<?php
require __DIR__ . '/ConsoleInitAppHelper.php';
require $app_package_path . 'LoadConfig.php';
$cookie_version = $_COOKIE[VERSION_KEY] ?? '';
$cookie_version = trim($cookie_version);
$version_val = $version_val_no_prefix = '';
$is_real_outer_access = ConsoleInitAppHelper::isRealOuterAccess();
$cookie_flag = false;
if ($is_real_outer_access || (!$is_real_outer_access && 'ga' === $cookie_version)) {
// 外部用户或者内部设置cookie为ga,只允许访问文件定义的ga版本
$file_tag = 'ga';
$file_version = file_get_contents($version_path . VERSION_KEY . '_ga');
} elseif (!$is_real_outer_access && 'beta' === $cookie_version) {
// 内部设置cookie为beta,只允许访问文件定义的beta版本
$file_tag = 'beta';
$file_version = file_get_contents($version_path . VERSION_KEY . '_beta');
} else {
$is_online_host = ConsoleInitAppHelper::isOnlineHost();
if (true === $is_online_host) {
// 线上域名默认指向ga环境 即使设置cookie也无效
$file_tag = 'ga';
$file_version = file_get_contents($version_path . VERSION_KEY . '_ga');
} else {
// 其他来源查找cookie
if ($cookie_version && is_dir($base_path . $cookie_version)) {
$base_path = $base_path . $cookie_version . '/';
$version_val = 'cookie-' . $cookie_version;
$version_val_no_prefix = $cookie_version;
// header("fpf-version: " . $version_val);
}
}
$cookie_flag = true;
}
if (false === $cookie_flag) {
$file_version = trim($file_version);
if ($file_version && is_dir($base_path . $file_version)) {
$base_path = $base_path . $file_version . '/';
$version_val = $file_tag . '-' . $file_version;
$version_val_no_prefix = $file_version;
// header("fpf-version: " . $version_val);
}
}
$location_default_version = false;
if ($origin_base_path === $base_path) {
if ($is_real_outer_access || ConsoleInitAppHelper::isFromCompanyAccessOuterHost()) {
// 如果是外网用户或者公司访问公网域名且未定位到任何有效的代码目录,重新指向ga版本
$location_default_version = true;
} else {
// 没有读取任何版本目录
if ('test' === SERVICE_ENV) {
// 提测环境
$location_default_version = true;
} else {
// 本地开发环境
// header("fpf-version: local");
}
}
}
if (true === $location_default_version) {
// 如果是外网用户且未定位到任何有效的代码目录,重新指向ga版本
$file_tag = 'ga';
$file_version = file_get_contents($version_path . VERSION_KEY . '_ga');
$file_version = trim($file_version);
if ($file_version && is_dir($base_path . $file_version)) {
$base_path = $base_path . $file_version . '/';
$version_val = $file_tag . '-' . $file_version;
$version_val_no_prefix = $file_version;
// header("fpf-version: " . $version_val);
} else {
throw new Exception('服务器代码定位错误');
}
}
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');
$GLOBALS['GLOBAL_VERSION_VALUE'] = $version_val;
$GLOBALS['GLOBAL_VERSION_VALUE_NO_PTEFIX'] = $version_val_no_prefix;
$GLOBALS['GLOBAL_YII_SYSTEM_APP'] = $base_path . 'vendor/yii2_33cn/';
$GLOBALS['GLOBAL_YII_USER_APP'] = $base_path . 'application/';
require $GLOBAL_YII_SYSTEM_APP . 'vendor/autoload.php';
require $base_path . 'vendor/autoload.php';
require $GLOBAL_YII_SYSTEM_APP . 'vendor/yiisoft/yii2/Yii.php';
$config = require $app_package_path . 'app_config/' . MAIN_CONSOLE_CONFIG_FILE;
(new yii\console\Application($config))->run();
\ No newline at end of file
<?php
/* 需要修改的参数<< */
$index_root_path = '/mnt/d/data/';
$app_package_path = $index_root_path . 'inner_site/';
$base_path = $origin_base_path = $index_root_path . 'inner_site/zhaobi/';
defined('VERSION_KEY') or define('VERSION_KEY', 'inner_site_devops_version');
$version_path = $index_root_path . 'version/';
defined('SERVICE_ENV') or define('SERVICE_ENV', 'local');
defined('MAIN_CONSOLE_CONFIG_FILE') or define('MAIN_CONSOLE_CONFIG_FILE', 'devops_main_console.php');
/* 需要修改的参数>> */
\ No newline at end of file
<?php
#!/usr/bin/env php
require __DIR__ . '/devops-basic.php';
require dirname(__DIR__) . '/VersionApp.php';
\ No newline at end of file
#!/usr/bin/env php
<?php
/* 需要修改的参数<< */
$index_root_path = '/mnt/d/data/';
defined('AUTO_LOAD_INDEX') or define('AUTO_LOAD_INDEX', $index_root_path . 'index/inner_site/devops/devops-swoole-for-console.php');
defined('IS_FORCE_ONLINE') or define('IS_FORCE_ONLINE', false);
/* 需要修改的参数>> */
defined('IS_SWOOLE_SERVICE') or define('IS_SWOOLE_SERVICE', true);
$swoole_middle_path = $index_root_path . 'swoft_service_middleware/';
defined('SWOOLE_MIDDLE_ROOT') or define('SWOOLE_MIDDLE_ROOT', $swoole_middle_path);
require_once SWOOLE_MIDDLE_ROOT . 'vendor/autoload.php';
require_once SWOOLE_MIDDLE_ROOT . 'vendor/swoft_33cn/vendor/autoload.php';
require_once __DIR__ . '/swoole/config/define.php';
// init the factory of bean
\Swoft\Bean\BeanFactory::init();
/* @var \Swoft\Bootstrap\Boots\Bootable $bootstrap*/
$bootstrap = \Swoft\App::getBean(\Swoft\Bootstrap\Bootstrap::class);
$bootstrap->bootstrap();
$console = new \Swoft\Console\Console();
$console->run();
\ No newline at end of file
## swoole 启动说明
> sudo php devops-swoole.php start
\ No newline at end of file
<?php
/*
* This file is part of Swoft.
* (c) Swoft <group@swoft.org>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
return [
'serverDispatcher' => [
'middlewares' => [
\Swoft\View\Middleware\ViewMiddleware::class,
// \Swoft\Devtool\Middleware\DevToolMiddleware::class,
// \Swoft\Session\Middleware\SessionMiddleware::class,
]
],
'httpRouter' => [
'ignoreLastSlash' => false,
'tmpCacheNumber' => 1000,
'matchAll' => '',
],
'requestParser' => [
'parsers' => [],
],
'view' => [
'viewsPath' => '@resources/views/',
],
'cache' => [
'driver' => 'redis',
],
'demoRedis' => [
'class' => \Swoft\Redis\Redis::class,
'poolName' => 'demoRedis'
]
];
<?php
/*
* This file is part of Swoft.
* (c) Swoft <group@swoft.org>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
return [];
\ No newline at end of file
<?php
/*
* This file is part of Swoft.
* (c) Swoft <group@swoft.org>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
return [
'noticeHandler' => [
'class' => \Swoft\Log\FileHandler::class,
'logFile' => '@runtime/logs/notice.log',
'formatter' => '${lineFormatter}',
'levels' => [
\Swoft\Log\Logger::NOTICE,
\Swoft\Log\Logger::INFO,
\Swoft\Log\Logger::DEBUG,
\Swoft\Log\Logger::TRACE,
],
],
'applicationHandler' => [
'class' => \Swoft\Log\FileHandler::class,
'logFile' => '@runtime/logs/error.log',
'formatter' => '${lineFormatter}',
'levels' => [
\Swoft\Log\Logger::ERROR,
\Swoft\Log\Logger::WARNING,
],
],
'logger' => [
'name' => APP_NAME,
'enable' => env('LOG_ENABLE', false),
'flushInterval' => 100,
'flushRequest' => true,
'handlers' => [
'${noticeHandler}',
'${applicationHandler}',
],
],
];
<?php
/*
* This file is part of Swoft.
* (c) Swoft <group@swoft.org>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
return [];
\ No newline at end of file
<?php
/*
* This file is part of Swoft.
* (c) Swoft <group@swoft.org>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
!defined('DS') && define('DS', DIRECTORY_SEPARATOR);
// App name
!defined('APP_NAME') && define('APP_NAME', 'swoft');
// Project base path
!defined('BASE_PATH') && define('BASE_PATH', SWOOLE_MIDDLE_ROOT . DIRECTORY_SEPARATOR . 'application/');
// Register alias
$aliases = [
'@root' => BASE_PATH,
'@env' => '@root',
'@app' => '@root/app',
'@res' => '@root/resources',
'@runtime' => '@root/runtime',
'@configs' => __DIR__,
'@resources' => '@root/resources',
'@beans' => '@configs/beans',
'@properties' => '@configs/properties',
'@console' => '@beans/console.php',
'@commands' => '@app/command',
'@vendor' => '@root/vendor',
];
\Swoft\App::setAliases($aliases);
<?php
/*
* This file is part of Swoft.
* (c) Swoft <group@swoft.org>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
return [
'env' => env('APP_ENV', 'test'),
'debug' => env('APP_DEBUG', false),
'version' => '1.0',
'autoInitBean' => true,
'bootScan' => [
'App\Commands',
'App\Boot',
],
'excludeScan' => [],
'I18n' => [
'sourceLanguage' => '@root/resources/messages/',
],
'db' => require __DIR__ . DS . 'db.php',
'cache' => require __DIR__ . DS . 'cache.php',
'service' => require __DIR__ . DS . 'service.php',
'breaker' => require __DIR__ . DS . 'breaker.php',
'provider' => require __DIR__ . DS . 'provider.php',
];
<?php
/*
* This file is part of Swoft.
* (c) Swoft <group@swoft.org>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
return [
'user' => [
'failCount' => 3,
'successCount' => 3,
'delayTime' => 500,
],
];
\ No newline at end of file
<?php
/*
* This file is part of Swoft.
* (c) Swoft <group@swoft.org>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
return [
'redis' => [
'name' => 'redis',
'uri' => [
'127.0.0.1:6379',
'127.0.0.1:6379',
],
'minActive' => 8,
'maxActive' => 8,
'maxWait' => 8,
'maxWaitTime' => 3,
'maxIdleTime' => 60,
'timeout' => 8,
'db' => 1,
'prefix' => 'redis_',
'serialize' => 0,
],
'demoRedis' => [
'db' => 2,
'prefix' => 'demo_redis_',
],
];
\ No newline at end of file
<?php
/*
* This file is part of Swoft.
* (c) Swoft <group@swoft.org>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
return [
'master' => [
'name' => 'master',
'uri' => [
'127.0.0.1:3306/test?user=root&password=123456&charset=utf8',
'127.0.0.1:3306/test?user=root&password=123456&charset=utf8',
],
'minActive' => 8,
'maxActive' => 8,
'maxWait' => 8,
'timeout' => 8,
'maxIdleTime' => 60,
'maxWaitTime' => 3,
],
'slave' => [
'name' => 'slave',
'uri' => [
'127.0.0.1:3306/test?user=root&password=123456&charset=utf8',
'127.0.0.1:3306/test?user=root&password=123456&charset=utf8',
],
'minActive' => 8,
'maxActive' => 8,
'maxWait' => 8,
'timeout' => 8,
'maxIdleTime' => 60,
'maxWaitTime' => 3,
],
];
\ No newline at end of file
<?php
/*
* This file is part of Swoft.
* (c) Swoft <group@swoft.org>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
return [
'consul' => [
'address' => '',
'port' => 8500,
'register' => [
'id' => '',
'name' => '',
'tags' => [],
'enableTagOverride' => false,
'service' => [
'address' => 'localhost',
'port' => '8099',
],
'check' => [
'id' => '',
'name' => '',
'tcp' => 'localhost:8099',
'interval' => 10,
'timeout' => 1,
],
],
'discovery' => [
'name' => 'user',
'dc' => 'dc',
'near' => '',
'tag' => '',
'passing' => true
]
],
];
\ No newline at end of file
<?php
/*
* This file is part of Swoft.
* (c) Swoft <group@swoft.org>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
return [
'user' => [
'name' => 'redis',
'uri' => [
'127.0.0.1:8099',
'127.0.0.1:8099',
],
'minActive' => 8,
'maxActive' => 8,
'maxWait' => 8,
'maxWaitTime' => 3,
'maxIdleTime' => 60,
'timeout' => 8,
'useProvider' => false,
'balancer' => 'random',
'provider' => 'consul',
]
];
\ No newline at end of file
<?php
/*
* This file is part of Swoft.
* (c) Swoft <group@swoft.org>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
return [
'server' => [
'pfile' => env('PFILE', '/tmp/devops_swoole.pid'),
'pname' => env('PNAME', 'php-swoft'),
'tcpable' => env('TCPABLE', true),
'cronable' => env('CRONABLE', false),
'autoReload' => env('AUTO_RELOAD', true),
],
'tcp' => [
'host' => env('TCP_HOST', '0.0.0.0'),
'port' => env('TCP_PORT', 8102),
'mode' => env('TCP_MODE', SWOOLE_PROCESS),
'type' => env('TCP_TYPE', SWOOLE_SOCK_TCP),
'package_max_length' => env('TCP_PACKAGE_MAX_LENGTH', 2048),
'open_eof_check' => env('TCP_OPEN_EOF_CHECK', false),
],
'http' => [
'host' => env('HTTP_HOST', '0.0.0.0'),
'port' => env('HTTP_PORT', 9501),
'mode' => env('HTTP_MODE', SWOOLE_PROCESS),
'type' => env('HTTP_TYPE', SWOOLE_SOCK_TCP),
],
'ws' => [
// enable handle http request ?
'enable_http' => env('WS_ENABLE_HTTP', true),
// other settings will extend the 'http' config
// you can define separately to overwrite existing settings
],
'crontab' => [
'task_count' => env('CRONTAB_TASK_COUNT', 1024),
'task_queue' => env('CRONTAB_TASK_QUEUE', 2048),
],
'setting' => [
'worker_num' => env('WORKER_NUM', 1),
'max_request' => env('MAX_REQUEST', 10000),
'daemonize' => env('DAEMONIZE', 0),
'dispatch_mode' => env('DISPATCH_MODE', 2),
'log_file' => env('LOG_FILE', '@runtime/logs/swoole.log'),
'task_worker_num' => env('TASK_WORKER_NUM', 1),
'package_max_length' => env('PACKAGE_MAX_LENGTH', 2048),
'upload_tmp_dir' => env('UPLOAD_TMP_DIR', '@runtime/uploadfiles'),
'document_root' => env('DOCUMENT_ROOT', BASE_PATH . '/public'),
'enable_static_handler' => env('ENABLE_STATIC_HANDLER', true),
'open_http2_protocol' => env('OPEN_HTTP2_PROTOCOL', false),
'ssl_cert_file' => env('SSL_CERT_FILE', ''),
'ssl_key_file' => env('SSL_KEY_FILE', ''),
'task_ipc_mode' => env('TASK_IPC_MODE', 1),
'message_queue_key' => env('MESSAGE_QUEUE_KEY', 0x70001001),
'task_tmpdir' => env('TASK_TMPDIR', '/tmp'),
],
];
#!/bin/bash
while true; do php7.0 /mnt/d/data/console/user_site/zhaobi-job.php latest-deal > /dev/null 2>&1; sleep 2; done &
#!/bin/bash
while true; do php7.0 /mnt/d/data/console/user_site/zhaobi-job.php rise-fall > /dev/null 2>&1; sleep 2; done &
#!/bin/bash
while true; do php7.0 /mnt/d/data/console/user_site/zhaobi-job.php usd-cny-rate > /dev/null 2>&1; sleep 2; done &
<?php
/* 需要修改的参数<< */
$index_root_path = '/mnt/d/data/';
$app_package_path = $index_root_path . 'thrift_impl/';
$base_path = $origin_base_path = $index_root_path . 'thrift_impl/market-service-impl/';
defined('VERSION_KEY') or define('VERSION_KEY', 'thrift_impl_market_version');
$version_path = $index_root_path . 'version/';
defined('SERVICE_ENV') or define('SERVICE_ENV', 'local');
defined('MAIN_CONSOLE_CONFIG_FILE') or define('MAIN_CONSOLE_CONFIG_FILE', 'market_main_console.php');
/* 需要修改的参数>> */
\ No newline at end of file
<?php
#!/usr/bin/env php
require __DIR__ . '/market-basic.php';
require dirname(dirname(__DIR__)) . '/VersionApp.php';
\ No newline at end of file
#!/usr/bin/env php
<?php
/* 需要修改的参数<< */
$index_root_path = '/mnt/d/data/';
defined('AUTO_LOAD_INDEX') or define('AUTO_LOAD_INDEX', $index_root_path . 'index/thrift_impl/market/market-swoole-for-console.php');
defined('IS_FORCE_ONLINE') or define('IS_FORCE_ONLINE', true);
/* 需要修改的参数>> */
defined('IS_SWOOLE_SERVICE') or define('IS_SWOOLE_SERVICE', true);
$swoole_middle_path = $index_root_path . 'swoft_service_middleware/';
defined('SWOOLE_MIDDLE_ROOT') or define('SWOOLE_MIDDLE_ROOT', $swoole_middle_path);
require_once SWOOLE_MIDDLE_ROOT . 'vendor/autoload.php';
require_once SWOOLE_MIDDLE_ROOT . 'vendor/swoft_33cn/vendor/autoload.php';
require_once __DIR__ . '/swoole/config/define.php';
// init the factory of bean
\Swoft\Bean\BeanFactory::init();
/* @var \Swoft\Bootstrap\Boots\Bootable $bootstrap*/
$bootstrap = \Swoft\App::getBean(\Swoft\Bootstrap\Bootstrap::class);
$bootstrap->bootstrap();
$console = new \Swoft\Console\Console();
$console->run();
\ No newline at end of file
## swoole 启动说明
> sudo php market-swoole.php start
\ No newline at end of file
<?php
/*
* This file is part of Swoft.
* (c) Swoft <group@swoft.org>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
return [
'serverDispatcher' => [
'middlewares' => [
\Swoft\View\Middleware\ViewMiddleware::class,
// \Swoft\Devtool\Middleware\DevToolMiddleware::class,
// \Swoft\Session\Middleware\SessionMiddleware::class,
]
],
'httpRouter' => [
'ignoreLastSlash' => false,
'tmpCacheNumber' => 1000,
'matchAll' => '',
],
'requestParser' => [
'parsers' => [],
],
'view' => [
'viewsPath' => '@resources/views/',
],
'cache' => [
'driver' => 'redis',
],
'demoRedis' => [
'class' => \Swoft\Redis\Redis::class,
'poolName' => 'demoRedis'
]
];
<?php
/*
* This file is part of Swoft.
* (c) Swoft <group@swoft.org>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
return [];
\ No newline at end of file
<?php
/*
* This file is part of Swoft.
* (c) Swoft <group@swoft.org>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
return [
'noticeHandler' => [
'class' => \Swoft\Log\FileHandler::class,
'logFile' => '@runtime/logs/notice.log',
'formatter' => '${lineFormatter}',
'levels' => [
\Swoft\Log\Logger::NOTICE,
\Swoft\Log\Logger::INFO,
\Swoft\Log\Logger::DEBUG,
\Swoft\Log\Logger::TRACE,
],
],
'applicationHandler' => [
'class' => \Swoft\Log\FileHandler::class,
'logFile' => '@runtime/logs/error.log',
'formatter' => '${lineFormatter}',
'levels' => [
\Swoft\Log\Logger::ERROR,
\Swoft\Log\Logger::WARNING,
],
],
'logger' => [
'name' => APP_NAME,
'enable' => env('LOG_ENABLE', false),
'flushInterval' => 100,
'flushRequest' => true,
'handlers' => [
'${noticeHandler}',
'${applicationHandler}',
],
],
];
<?php
/*
* This file is part of Swoft.
* (c) Swoft <group@swoft.org>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
return [];
\ No newline at end of file
<?php
/*
* This file is part of Swoft.
* (c) Swoft <group@swoft.org>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
!defined('DS') && define('DS', DIRECTORY_SEPARATOR);
// App name
!defined('APP_NAME') && define('APP_NAME', 'swoft');
// Project base path
!defined('BASE_PATH') && define('BASE_PATH', SWOOLE_MIDDLE_ROOT . DIRECTORY_SEPARATOR . 'application/');
// Register alias
$aliases = [
'@root' => BASE_PATH,
'@env' => '@root',
'@app' => '@root/app',
'@res' => '@root/resources',
'@runtime' => '@root/runtime',
'@configs' => __DIR__,
'@resources' => '@root/resources',
'@beans' => '@configs/beans',
'@properties' => '@configs/properties',
'@console' => '@beans/console.php',
'@commands' => '@app/command',
'@vendor' => '@root/vendor',
];
\Swoft\App::setAliases($aliases);
<?php
/*
* This file is part of Swoft.
* (c) Swoft <group@swoft.org>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
return [
'env' => env('APP_ENV', 'test'),
'debug' => env('APP_DEBUG', false),
'version' => '1.0',
'autoInitBean' => true,
'bootScan' => [
'App\Commands',
'App\Boot',
],
'excludeScan' => [],
'I18n' => [
'sourceLanguage' => '@root/resources/messages/',
],
'db' => require __DIR__ . DS . 'db.php',
'cache' => require __DIR__ . DS . 'cache.php',
'service' => require __DIR__ . DS . 'service.php',
'breaker' => require __DIR__ . DS . 'breaker.php',
'provider' => require __DIR__ . DS . 'provider.php',
];
<?php
/*
* This file is part of Swoft.
* (c) Swoft <group@swoft.org>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
return [
'user' => [
'failCount' => 3,
'successCount' => 3,
'delayTime' => 500,
],
];
\ No newline at end of file
<?php
/*
* This file is part of Swoft.
* (c) Swoft <group@swoft.org>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
return [
'redis' => [
'name' => 'redis',
'uri' => [
'127.0.0.1:6379',
'127.0.0.1:6379',
],
'minActive' => 8,
'maxActive' => 8,
'maxWait' => 8,
'maxWaitTime' => 3,
'maxIdleTime' => 60,
'timeout' => 8,
'db' => 1,
'prefix' => 'redis_',
'serialize' => 0,
],
'demoRedis' => [
'db' => 2,
'prefix' => 'demo_redis_',
],
];
\ No newline at end of file
<?php
/*
* This file is part of Swoft.
* (c) Swoft <group@swoft.org>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
return [
'master' => [
'name' => 'master',
'uri' => [
'127.0.0.1:3306/test?user=root&password=123456&charset=utf8',
'127.0.0.1:3306/test?user=root&password=123456&charset=utf8',
],
'minActive' => 8,
'maxActive' => 8,
'maxWait' => 8,
'timeout' => 8,
'maxIdleTime' => 60,
'maxWaitTime' => 3,
],
'slave' => [
'name' => 'slave',
'uri' => [
'127.0.0.1:3306/test?user=root&password=123456&charset=utf8',
'127.0.0.1:3306/test?user=root&password=123456&charset=utf8',
],
'minActive' => 8,
'maxActive' => 8,
'maxWait' => 8,
'timeout' => 8,
'maxIdleTime' => 60,
'maxWaitTime' => 3,
],
];
\ No newline at end of file
<?php
/*
* This file is part of Swoft.
* (c) Swoft <group@swoft.org>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
return [
'consul' => [
'address' => '',
'port' => 8500,
'register' => [
'id' => '',
'name' => '',
'tags' => [],
'enableTagOverride' => false,
'service' => [
'address' => 'localhost',
'port' => '8099',
],
'check' => [
'id' => '',
'name' => '',
'tcp' => 'localhost:8099',
'interval' => 10,
'timeout' => 1,
],
],
'discovery' => [
'name' => 'user',
'dc' => 'dc',
'near' => '',
'tag' => '',
'passing' => true
]
],
];
\ No newline at end of file
<?php
/*
* This file is part of Swoft.
* (c) Swoft <group@swoft.org>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
return [
'user' => [
'name' => 'redis',
'uri' => [
'127.0.0.1:8099',
'127.0.0.1:8099',
],
'minActive' => 8,
'maxActive' => 8,
'maxWait' => 8,
'maxWaitTime' => 3,
'maxIdleTime' => 60,
'timeout' => 8,
'useProvider' => false,
'balancer' => 'random',
'provider' => 'consul',
]
];
\ No newline at end of file
<?php
/*
* This file is part of Swoft.
* (c) Swoft <group@swoft.org>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
return [
'server' => [
'pfile' => env('PFILE', '/tmp/market_swoole.pid'),
'pname' => env('PNAME', 'php-swoft'),
'tcpable' => env('TCPABLE', true),
'cronable' => env('CRONABLE', false),
'autoReload' => env('AUTO_RELOAD', true),
],
'tcp' => [
'host' => env('TCP_HOST', '0.0.0.0'),
'port' => env('TCP_PORT', 8101),
'mode' => env('TCP_MODE', SWOOLE_PROCESS),
'type' => env('TCP_TYPE', SWOOLE_SOCK_TCP),
'package_max_length' => env('TCP_PACKAGE_MAX_LENGTH', 2048),
'open_eof_check' => env('TCP_OPEN_EOF_CHECK', false),
],
'http' => [
'host' => env('HTTP_HOST', '0.0.0.0'),
'port' => env('HTTP_PORT', 9504),
'mode' => env('HTTP_MODE', SWOOLE_PROCESS),
'type' => env('HTTP_TYPE', SWOOLE_SOCK_TCP),
],
'ws' => [
// enable handle http request ?
'enable_http' => env('WS_ENABLE_HTTP', true),
// other settings will extend the 'http' config
// you can define separately to overwrite existing settings
],
'crontab' => [
'task_count' => env('CRONTAB_TASK_COUNT', 1024),
'task_queue' => env('CRONTAB_TASK_QUEUE', 2048),
],
'setting' => [
'worker_num' => env('WORKER_NUM', 1),
'max_request' => env('MAX_REQUEST', 10000),
'daemonize' => env('DAEMONIZE', 0),
'dispatch_mode' => env('DISPATCH_MODE', 2),
'log_file' => env('LOG_FILE', '@runtime/logs/swoole.log'),
'task_worker_num' => env('TASK_WORKER_NUM', 1),
'package_max_length' => env('PACKAGE_MAX_LENGTH', 2048),
'upload_tmp_dir' => env('UPLOAD_TMP_DIR', '@runtime/uploadfiles'),
'document_root' => env('DOCUMENT_ROOT', BASE_PATH . '/public'),
'enable_static_handler' => env('ENABLE_STATIC_HANDLER', true),
'open_http2_protocol' => env('OPEN_HTTP2_PROTOCOL', false),
'ssl_cert_file' => env('SSL_CERT_FILE', ''),
'ssl_key_file' => env('SSL_KEY_FILE', ''),
'task_ipc_mode' => env('TASK_IPC_MODE', 1),
'message_queue_key' => env('MESSAGE_QUEUE_KEY', 0x70001001),
'task_tmpdir' => env('TASK_TMPDIR', '/tmp'),
],
];
## swoole 启动说明
> sudo php zhaobi-swoole.php start
\ No newline at end of file
<?php
/*
* This file is part of Swoft.
* (c) Swoft <group@swoft.org>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
return [
'serverDispatcher' => [
'middlewares' => [
\Swoft\View\Middleware\ViewMiddleware::class,
// \Swoft\Devtool\Middleware\DevToolMiddleware::class,
// \Swoft\Session\Middleware\SessionMiddleware::class,
]
],
'httpRouter' => [
'ignoreLastSlash' => false,
'tmpCacheNumber' => 1000,
'matchAll' => '',
],
'requestParser' => [
'parsers' => [],
],
'view' => [
'viewsPath' => '@resources/views/',
],
'cache' => [
'driver' => 'redis',
],
'demoRedis' => [
'class' => \Swoft\Redis\Redis::class,
'poolName' => 'demoRedis'
]
];
<?php
/*
* This file is part of Swoft.
* (c) Swoft <group@swoft.org>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
return [];
\ No newline at end of file
<?php
/*
* This file is part of Swoft.
* (c) Swoft <group@swoft.org>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
return [
'noticeHandler' => [
'class' => \Swoft\Log\FileHandler::class,
'logFile' => '@runtime/logs/notice.log',
'formatter' => '${lineFormatter}',
'levels' => [
\Swoft\Log\Logger::NOTICE,
\Swoft\Log\Logger::INFO,
\Swoft\Log\Logger::DEBUG,
\Swoft\Log\Logger::TRACE,
],
],
'applicationHandler' => [
'class' => \Swoft\Log\FileHandler::class,
'logFile' => '@runtime/logs/error.log',
'formatter' => '${lineFormatter}',
'levels' => [
\Swoft\Log\Logger::ERROR,
\Swoft\Log\Logger::WARNING,
],
],
'logger' => [
'name' => APP_NAME,
'enable' => env('LOG_ENABLE', false),
'flushInterval' => 100,
'flushRequest' => true,
'handlers' => [
'${noticeHandler}',
'${applicationHandler}',
],
],
];
<?php
/*
* This file is part of Swoft.
* (c) Swoft <group@swoft.org>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
return [];
\ No newline at end of file
<?php
/*
* This file is part of Swoft.
* (c) Swoft <group@swoft.org>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
!defined('DS') && define('DS', DIRECTORY_SEPARATOR);
// App name
!defined('APP_NAME') && define('APP_NAME', 'swoft');
// Project base path
!defined('BASE_PATH') && define('BASE_PATH', SWOOLE_MIDDLE_ROOT . DIRECTORY_SEPARATOR . 'application/');
// Register alias
$aliases = [
'@root' => BASE_PATH,
'@env' => '@root',
'@app' => '@root/app',
'@res' => '@root/resources',
'@runtime' => '@root/runtime',
'@configs' => __DIR__,
'@resources' => '@root/resources',
'@beans' => '@configs/beans',
'@properties' => '@configs/properties',
'@console' => '@beans/console.php',
'@commands' => '@app/command',
'@vendor' => '@root/vendor',
];
\Swoft\App::setAliases($aliases);
<?php
/*
* This file is part of Swoft.
* (c) Swoft <group@swoft.org>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
return [
'env' => env('APP_ENV', 'test'),
'debug' => env('APP_DEBUG', false),
'version' => '1.0',
'autoInitBean' => true,
'bootScan' => [
'App\Commands',
'App\Boot',
],
'excludeScan' => [],
'I18n' => [
'sourceLanguage' => '@root/resources/messages/',
],
'db' => require __DIR__ . DS . 'db.php',
'cache' => require __DIR__ . DS . 'cache.php',
'service' => require __DIR__ . DS . 'service.php',
'breaker' => require __DIR__ . DS . 'breaker.php',
'provider' => require __DIR__ . DS . 'provider.php',
];
<?php
/*
* This file is part of Swoft.
* (c) Swoft <group@swoft.org>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
return [
'user' => [
'failCount' => 3,
'successCount' => 3,
'delayTime' => 500,
],
];
\ No newline at end of file
<?php
/*
* This file is part of Swoft.
* (c) Swoft <group@swoft.org>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
return [
'redis' => [
'name' => 'redis',
'uri' => [
'127.0.0.1:6379',
'127.0.0.1:6379',
],
'minActive' => 8,
'maxActive' => 8,
'maxWait' => 8,
'maxWaitTime' => 3,
'maxIdleTime' => 60,
'timeout' => 8,
'db' => 1,
'prefix' => 'redis_',
'serialize' => 0,
],
'demoRedis' => [
'db' => 2,
'prefix' => 'demo_redis_',
],
];
\ No newline at end of file
<?php
/*
* This file is part of Swoft.
* (c) Swoft <group@swoft.org>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
return [
'master' => [
'name' => 'master',
'uri' => [
'127.0.0.1:3306/test?user=root&password=123456&charset=utf8',
'127.0.0.1:3306/test?user=root&password=123456&charset=utf8',
],
'minActive' => 8,
'maxActive' => 8,
'maxWait' => 8,
'timeout' => 8,
'maxIdleTime' => 60,
'maxWaitTime' => 3,
],
'slave' => [
'name' => 'slave',
'uri' => [
'127.0.0.1:3306/test?user=root&password=123456&charset=utf8',
'127.0.0.1:3306/test?user=root&password=123456&charset=utf8',
],
'minActive' => 8,
'maxActive' => 8,
'maxWait' => 8,
'timeout' => 8,
'maxIdleTime' => 60,
'maxWaitTime' => 3,
],
];
\ No newline at end of file
<?php
/*
* This file is part of Swoft.
* (c) Swoft <group@swoft.org>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
return [
'consul' => [
'address' => '',
'port' => 8500,
'register' => [
'id' => '',
'name' => '',
'tags' => [],
'enableTagOverride' => false,
'service' => [
'address' => 'localhost',
'port' => '8099',
],
'check' => [
'id' => '',
'name' => '',
'tcp' => 'localhost:8099',
'interval' => 10,
'timeout' => 1,
],
],
'discovery' => [
'name' => 'user',
'dc' => 'dc',
'near' => '',
'tag' => '',
'passing' => true
]
],
];
\ No newline at end of file
<?php
/*
* This file is part of Swoft.
* (c) Swoft <group@swoft.org>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
return [
'user' => [
'name' => 'redis',
'uri' => [
'127.0.0.1:8099',
'127.0.0.1:8099',
],
'minActive' => 8,
'maxActive' => 8,
'maxWait' => 8,
'maxWaitTime' => 3,
'maxIdleTime' => 60,
'timeout' => 8,
'useProvider' => false,
'balancer' => 'random',
'provider' => 'consul',
]
];
\ No newline at end of file
<?php
/*
* This file is part of Swoft.
* (c) Swoft <group@swoft.org>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
return [
'server' => [
'pfile' => env('PFILE', '/tmp/zhaobi_swoft.pid'),
'pname' => env('PNAME', 'php-swoft'),
'tcpable' => env('TCPABLE', true),
'cronable' => env('CRONABLE', false),
'autoReload' => env('AUTO_RELOAD', true),
],
'tcp' => [
'host' => env('TCP_HOST', '0.0.0.0'),
'port' => env('TCP_PORT', 8103),
'mode' => env('TCP_MODE', SWOOLE_PROCESS),
'type' => env('TCP_TYPE', SWOOLE_SOCK_TCP),
'package_max_length' => env('TCP_PACKAGE_MAX_LENGTH', 2048),
'open_eof_check' => env('TCP_OPEN_EOF_CHECK', false),
],
'http' => [
'host' => env('HTTP_HOST', '0.0.0.0'),
'port' => env('HTTP_PORT', 9500),
'mode' => env('HTTP_MODE', SWOOLE_PROCESS),
'type' => env('HTTP_TYPE', SWOOLE_SOCK_TCP),
],
'ws' => [
// enable handle http request ?
'enable_http' => env('WS_ENABLE_HTTP', true),
// other settings will extend the 'http' config
// you can define separately to overwrite existing settings
],
'crontab' => [
'task_count' => env('CRONTAB_TASK_COUNT', 1024),
'task_queue' => env('CRONTAB_TASK_QUEUE', 2048),
],
'setting' => [
'worker_num' => env('WORKER_NUM', 1),
'max_request' => env('MAX_REQUEST', 10000),
'daemonize' => env('DAEMONIZE', 0),
'dispatch_mode' => env('DISPATCH_MODE', 2),
'log_file' => env('LOG_FILE', '@runtime/logs/swoole.log'),
'task_worker_num' => env('TASK_WORKER_NUM', 1),
'package_max_length' => env('PACKAGE_MAX_LENGTH', 2048),
'upload_tmp_dir' => env('UPLOAD_TMP_DIR', '@runtime/uploadfiles'),
'document_root' => env('DOCUMENT_ROOT', BASE_PATH . '/public'),
'enable_static_handler' => env('ENABLE_STATIC_HANDLER', true),
'open_http2_protocol' => env('OPEN_HTTP2_PROTOCOL', false),
'ssl_cert_file' => env('SSL_CERT_FILE', ''),
'ssl_key_file' => env('SSL_KEY_FILE', ''),
'task_ipc_mode' => env('TASK_IPC_MODE', 1),
'message_queue_key' => env('MESSAGE_QUEUE_KEY', 0x70001001),
'task_tmpdir' => env('TASK_TMPDIR', '/tmp'),
],
];
<?php
/* 需要修改的参数<< */
$index_root_path = '/mnt/d/data/';
$app_package_path = $index_root_path . 'user_site/';
$base_path = $origin_base_path = $index_root_path . 'user_site/zhaobi/';
defined('VERSION_KEY') or define('VERSION_KEY', 'user_site_zhaobi_version');
$version_path = $index_root_path . 'version/';
defined('SERVICE_ENV') or define('SERVICE_ENV', 'local');
defined('MAIN_CONSOLE_CONFIG_FILE') or define('MAIN_CONSOLE_CONFIG_FILE', 'zhaobi_main_console.php');
/* 需要修改的参数>> */
\ No newline at end of file
<?php
#!/usr/bin/env php
require __DIR__ . '/zhaobi-basic.php';
require dirname(__DIR__) . '/VersionApp.php';
\ No newline at end of file
#!/usr/bin/env php
<?php
/* 需要修改的参数<< */
$index_root_path = '/mnt/d/data/';
defined('AUTO_LOAD_INDEX') or define('AUTO_LOAD_INDEX', $index_root_path . 'index/user_site/zhaobi/zhaobi-swoole-for-console.php');
defined('IS_FORCE_ONLINE') or define('IS_FORCE_ONLINE', false);
/* 需要修改的参数>> */
defined('IS_SWOOLE_SERVICE') or define('IS_SWOOLE_SERVICE', true);
$swoole_middle_path = $index_root_path . 'swoft_service_middleware/';
defined('SWOOLE_MIDDLE_ROOT') or define('SWOOLE_MIDDLE_ROOT', $swoole_middle_path);
require_once SWOOLE_MIDDLE_ROOT . 'vendor/autoload.php';
require_once SWOOLE_MIDDLE_ROOT . 'vendor/swoft_33cn/vendor/autoload.php';
require_once __DIR__ . '/swoole/config/define.php';
// init the factory of bean
\Swoft\Bean\BeanFactory::init();
/* @var \Swoft\Bootstrap\Boots\Bootable $bootstrap*/
$bootstrap = \Swoft\App::getBean(\Swoft\Bootstrap\Bootstrap::class);
$bootstrap->bootstrap();
$console = new \Swoft\Console\Console();
$console->run();
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment