Commit d5c76431 by yangsh

添加环境变量,去掉日志

parent b692e548
......@@ -13,3 +13,4 @@ DB_NAME=cdzpay
DB_PASSWORD=senthink123
DB_PORT=3306
DB_HOST=127.0.0.1
API_DOMAIN=https://cdzpay.staging.senthink.com
\ No newline at end of file
......@@ -15,7 +15,7 @@ define('APP', 'Application\\Controller\\');
class Events
{
const API_DOMAIN = 'https://cdzpay.test.senthink.com';
// const API_DOMAIN = 'https://cdzpay.test.senthink.com';
public static function onWorkerStart()
......@@ -47,7 +47,6 @@ class Events
}
\Lib\Log::debug($message);
$command = $request['command'];
......@@ -62,7 +61,7 @@ class Events
$client = new Client([
'base_uri' => self::API_DOMAIN,
'base_uri' => getenv('API_DOMAIN'),
]);
$token = $request['token'];
......@@ -96,7 +95,7 @@ class Events
if (isset($request['super_agent_id'])) {
$redis = new \Redis();
$redis->connect('redis.test.senthink.com');
$redis->connect('redis.default.svc.cluster.local');
$redis->select(4);
$redis->multi(2);
foreach ($request['super_agent_id'] as $id) {
......
......@@ -21,7 +21,7 @@ $worker->name = 'senthink_web_app_push';
// bussinessWorker进程数量
$worker->count = 1;
// 服务注册地址
$worker->registerAddress = \Lib\Env::get('REGISTER_IP').':'.\Lib\Env::get('REGISTER_PORT');
$worker->registerAddress = getenv('REGISTER_IP').':'.getenv('REGISTER_PORT');
// 如果不是在根目录启动,则运行runAll方法
if(!defined('GLOBAL_START')) {
......
......@@ -17,20 +17,20 @@ use Lib\Env;
// gateway 进程,这里使用Text协议,可以用telnet测试
$gateway = new Gateway("websocket://0.0.0.0:8283");
// gateway名称,status方便查看
$gateway->name = Env::get('GATEWAY_NAME');
$gateway->name = getenv('GATEWAY_NAME');
// gateway进程数
$gateway->count = Env::get('GATEWAY_COUNT');
$gateway->count = getenv('GATEWAY_COUNT');
// 本机ip,分布式部署时使用内网ip
$gateway->lanIp = Env::get('GATEWAY_IP');
$gateway->lanIp = getenv('GATEWAY_IP');
// 内部通讯起始端口,假如$gateway->count=4,起始端口为4000
// 则一般会使用4000 4001 4002 4003 4个端口作为内部通讯端口
$gateway->startPort = Env::get('GATEWAY_START_PORT');
$gateway->startPort = getenv('GATEWAY_START_PORT');
// 服务注册地址
$gateway->registerAddress = Env::get('REGISTER_IP').':'.Env::get('REGISTER_PORT');
$gateway->registerAddress = getenv('REGISTER_IP').':'.getenv('REGISTER_PORT');
// 心跳间隔
$gateway->pingInterval = 30;
......
......@@ -16,7 +16,7 @@ use \GatewayWorker\Register;
use Lib\Env;
// register 服务必须是text协议
$register = new Register('text://'.Env::get('REGISTER_IP').':'.Env::get('REGISTER_PORT'));
$register = new Register('text://'.getenv('REGISTER_IP').':'.getenv('REGISTER_PORT'));
// 如果不是在根目录启动,则运行runAll方法
......
......@@ -85,7 +85,7 @@ class Env
static::boot();
}
$files = static::$env['START_FILES'];
$files = static::$e['START_FILES'];
$files = explode('|',$files);
......
......@@ -3,7 +3,8 @@
"workerman/gateway-worker": "^3.0",
"workerman/mysql": "^1.0",
"monolog/monolog": "^1.23",
"guzzlehttp/guzzle": "^6.3"
"guzzlehttp/guzzle": "^6.3",
"vlucas/phpdotenv": "^2.5"
},
"autoload": {
"psr-4": {
......
......@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "5e3071f271d42e2e0ca4014c09b4a61e",
"content-hash": "02b5d88f17afcedf8167b98500a3005c",
"packages": [
{
"name": "guzzlehttp/guzzle",
......@@ -363,6 +363,56 @@
"time": "2016-10-10T12:19:37+00:00"
},
{
"name": "vlucas/phpdotenv",
"version": "v2.5.1",
"source": {
"type": "git",
"url": "https://github.com/vlucas/phpdotenv.git",
"reference": "8abb4f9aa89ddea9d52112c65bbe8d0125e2fa8e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/8abb4f9aa89ddea9d52112c65bbe8d0125e2fa8e",
"reference": "8abb4f9aa89ddea9d52112c65bbe8d0125e2fa8e",
"shasum": ""
},
"require": {
"php": ">=5.3.9"
},
"require-dev": {
"phpunit/phpunit": "^4.8.35 || ^5.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.5-dev"
}
},
"autoload": {
"psr-4": {
"Dotenv\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Vance Lucas",
"email": "vance@vancelucas.com",
"homepage": "http://www.vancelucas.com"
}
],
"description": "Loads environment variables from `.env` to `getenv()`, `$_ENV` and `$_SERVER` automagically.",
"keywords": [
"dotenv",
"env",
"environment"
],
"time": "2018-07-29T20:33:41+00:00"
},
{
"name": "workerman/gateway-worker",
"version": "v3.0.9",
"source": {
......
......@@ -27,43 +27,21 @@ define('GLOBAL_START', 1);
require_once __DIR__ . '/vendor/autoload.php';
/**
* @param $exception
*/
function exceptionHandle($exception)
{
$logger = new \Monolog\Logger('error');
$logger->pushHandler(new \Monolog\Handler\RotatingFileHandler('./storage/log/error', 30));
try{
$logger->error($exception->getMessage(),[
$exception->getFile(),
$exception->getTraceAsString(),
$exception->getLine(),
$exception->getTrace(),
]);
}catch (Exception $exception)
{
error_log($exception->getMessage());
}
}
$dotenv = new \Dotenv\Dotenv(__DIR__);
$dotenv->load();
set_exception_handler('exceptionHandle');
$start_file = getenv('START_FILES');
$files = explode('|', $start_file);
// 加载所有Applications/*/start.php,以便启动所有服务
foreach (glob(__DIR__ . '/Application/start*.php') as $start_file) {
foreach (Env::getStartFiles() as $file)
{
if(strstr($start_file,$file))
{
foreach ($files as $file) {
if (strstr($start_file, $file)) {
require_once $start_file;
}
}
......@@ -71,7 +49,6 @@ foreach (glob(__DIR__ . '/Application/start*.php') as $start_file) {
//require_once $start_file;
}
\Lib\Log::bootLog();
Worker::runAll();
\ No newline at end of file
......@@ -377,7 +377,7 @@ class ClassLoader
$subPath = $class;
while (false !== $lastPos = strrpos($subPath, '\\')) {
$subPath = substr($subPath, 0, $lastPos);
$search = $subPath.'\\';
$search = $subPath . '\\';
if (isset($this->prefixDirsPsr4[$search])) {
$pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1);
foreach ($this->prefixDirsPsr4[$search] as $dir) {
......
......@@ -17,5 +17,6 @@ return array(
'GuzzleHttp\\Promise\\' => array($vendorDir . '/guzzlehttp/promises/src'),
'GuzzleHttp\\' => array($vendorDir . '/guzzlehttp/guzzle/src'),
'GatewayWorker\\' => array($vendorDir . '/workerman/gateway-worker/src'),
'Dotenv\\' => array($vendorDir . '/vlucas/phpdotenv/src'),
'Application\\' => array($baseDir . '/Application'),
);
......@@ -42,6 +42,10 @@ class ComposerStaticInit31215f8a78f4727bf301167d9660a4fc
'GuzzleHttp\\' => 11,
'GatewayWorker\\' => 14,
),
'D' =>
array (
'Dotenv\\' => 7,
),
'A' =>
array (
'Application\\' => 12,
......@@ -93,6 +97,10 @@ class ComposerStaticInit31215f8a78f4727bf301167d9660a4fc
array (
0 => __DIR__ . '/..' . '/workerman/gateway-worker/src',
),
'Dotenv\\' =>
array (
0 => __DIR__ . '/..' . '/vlucas/phpdotenv/src',
),
'Application\\' =>
array (
0 => __DIR__ . '/../..' . '/Application',
......
......@@ -368,6 +368,58 @@
]
},
{
"name": "vlucas/phpdotenv",
"version": "v2.5.1",
"version_normalized": "2.5.1.0",
"source": {
"type": "git",
"url": "https://github.com/vlucas/phpdotenv.git",
"reference": "8abb4f9aa89ddea9d52112c65bbe8d0125e2fa8e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/8abb4f9aa89ddea9d52112c65bbe8d0125e2fa8e",
"reference": "8abb4f9aa89ddea9d52112c65bbe8d0125e2fa8e",
"shasum": ""
},
"require": {
"php": ">=5.3.9"
},
"require-dev": {
"phpunit/phpunit": "^4.8.35 || ^5.0"
},
"time": "2018-07-29T20:33:41+00:00",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.5-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-4": {
"Dotenv\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Vance Lucas",
"email": "vance@vancelucas.com",
"homepage": "http://www.vancelucas.com"
}
],
"description": "Loads environment variables from `.env` to `getenv()`, `$_ENV` and `$_SERVER` automagically.",
"keywords": [
"dotenv",
"env",
"environment"
]
},
{
"name": "workerman/gateway-worker",
"version": "v3.0.9",
"version_normalized": "3.0.9.0",
......
The BSD 3-Clause License
http://opensource.org/licenses/BSD-3-Clause
Copyright (c) 2013, Vance Lucas
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Vance Lucas nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
{
"name": "vlucas/phpdotenv",
"description": "Loads environment variables from `.env` to `getenv()`, `$_ENV` and `$_SERVER` automagically.",
"keywords": ["env", "dotenv", "environment"],
"license" : "BSD-3-Clause",
"authors" : [
{
"name": "Vance Lucas",
"email": "vance@vancelucas.com",
"homepage": "http://www.vancelucas.com"
}
],
"require": {
"php": ">=5.3.9"
},
"require-dev": {
"phpunit/phpunit": "^4.8.35 || ^5.0"
},
"autoload": {
"psr-4": {
"Dotenv\\": "src/"
}
},
"extra": {
"branch-alias": {
"dev-master": "2.5-dev"
}
}
}
<?php
namespace Dotenv;
use Dotenv\Exception\InvalidPathException;
/**
* This is the dotenv class.
*
* It's responsible for loading a `.env` file in the given directory and
* setting the environment vars.
*/
class Dotenv
{
/**
* The file path.
*
* @var string
*/
protected $filePath;
/**
* The loader instance.
*
* @var \Dotenv\Loader|null
*/
protected $loader;
/**
* Create a new dotenv instance.
*
* @param string $path
* @param string $file
*
* @return void
*/
public function __construct($path, $file = '.env')
{
$this->filePath = $this->getFilePath($path, $file);
$this->loader = new Loader($this->filePath, true);
}
/**
* Load environment file in given directory.
*
* @return array
*/
public function load()
{
return $this->loadData();
}
/**
* Load environment file in given directory, suppress InvalidPathException.
*
* @return array
*/
public function safeLoad()
{
try {
return $this->loadData();
} catch (InvalidPathException $e) {
// suppressing exception
return array();
}
}
/**
* Load environment file in given directory.
*
* @return array
*/
public function overload()
{
return $this->loadData(true);
}
/**
* Returns the full path to the file.
*
* @param string $path
* @param string $file
*
* @return string
*/
protected function getFilePath($path, $file)
{
if (!is_string($file)) {
$file = '.env';
}
$filePath = rtrim($path, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.$file;
return $filePath;
}
/**
* Actually load the data.
*
* @param bool $overload
*
* @return array
*/
protected function loadData($overload = false)
{
return $this->loader->setImmutable(!$overload)->load();
}
/**
* Required ensures that the specified variables exist, and returns a new validator object.
*
* @param string|string[] $variable
*
* @return \Dotenv\Validator
*/
public function required($variable)
{
return new Validator((array) $variable, $this->loader);
}
/**
* Get the list of environment variables declared inside the 'env' file.
*
* @return array
*/
public function getEnvironmentVariableNames()
{
return $this->loader->variableNames;
}
}
<?php
namespace Dotenv\Exception;
/**
* This is the exception interface.
*/
interface ExceptionInterface
{
//
}
<?php
namespace Dotenv\Exception;
use InvalidArgumentException;
/**
* This is the invalid callback exception class.
*/
class InvalidCallbackException extends InvalidArgumentException implements ExceptionInterface
{
//
}
<?php
namespace Dotenv\Exception;
use InvalidArgumentException;
/**
* This is the invalid file exception class.
*/
class InvalidFileException extends InvalidArgumentException implements ExceptionInterface
{
//
}
<?php
namespace Dotenv\Exception;
use InvalidArgumentException;
/**
* This is the invalid path exception class.
*/
class InvalidPathException extends InvalidArgumentException implements ExceptionInterface
{
//
}
<?php
namespace Dotenv\Exception;
use RuntimeException;
/**
* This is the validation exception class.
*/
class ValidationException extends RuntimeException implements ExceptionInterface
{
//
}
<?php
namespace Dotenv;
use Dotenv\Exception\InvalidCallbackException;
use Dotenv\Exception\ValidationException;
/**
* This is the validator class.
*
* It's responsible for applying validations against a number of variables.
*/
class Validator
{
/**
* The variables to validate.
*
* @var array
*/
protected $variables;
/**
* The loader instance.
*
* @var \Dotenv\Loader
*/
protected $loader;
/**
* Create a new validator instance.
*
* @param array $variables
* @param \Dotenv\Loader $loader
*
* @return void
*/
public function __construct(array $variables, Loader $loader)
{
$this->variables = $variables;
$this->loader = $loader;
$this->assertCallback(
function ($value) {
return $value !== null;
},
'is missing'
);
}
/**
* Assert that each variable is not empty.
*
* @return \Dotenv\Validator
*/
public function notEmpty()
{
return $this->assertCallback(
function ($value) {
return strlen(trim($value)) > 0;
},
'is empty'
);
}
/**
* Assert that each specified variable is an integer.
*
* @return \Dotenv\Validator
*/
public function isInteger()
{
return $this->assertCallback(
function ($value) {
return ctype_digit($value);
},
'is not an integer'
);
}
/**
* Assert that each specified variable is a boolean.
*
* @return \Dotenv\Validator
*/
public function isBoolean()
{
return $this->assertCallback(
function ($value) {
if ($value === '') {
return false;
}
return (filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) !== NULL);
},
'is not a boolean'
);
}
/**
* Assert that each variable is amongst the given choices.
*
* @param string[] $choices
*
* @return \Dotenv\Validator
*/
public function allowedValues(array $choices)
{
return $this->assertCallback(
function ($value) use ($choices) {
return in_array($value, $choices);
},
'is not an allowed value'
);
}
/**
* Assert that the callback returns true for each variable.
*
* @param callable $callback
* @param string $message
*
* @throws \Dotenv\Exception\InvalidCallbackException|\Dotenv\Exception\ValidationException
*
* @return \Dotenv\Validator
*/
protected function assertCallback($callback, $message = 'failed callback assertion')
{
if (!is_callable($callback)) {
throw new InvalidCallbackException('The provided callback must be callable.');
}
$variablesFailingAssertion = array();
foreach ($this->variables as $variableName) {
$variableValue = $this->loader->getEnvironmentVariable($variableName);
if (call_user_func($callback, $variableValue) === false) {
$variablesFailingAssertion[] = $variableName." $message";
}
}
if (count($variablesFailingAssertion) > 0) {
throw new ValidationException(sprintf(
'One or more environment variables failed assertions: %s.',
implode(', ', $variablesFailingAssertion)
));
}
return $this;
}
}
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