구성 파일
위치
webman의 구성 파일은 config/
디렉토리 아래에 있으며, 프로젝트 내에서 config()
함수를 통해 해당 구성을 가져올 수 있습니다.
구성 가져오기
모든 구성 가져오기
config();
config/app.php
의 모든 구성 가져오기
config('app');
config/app.php
의 debug
구성 가져오기
config('app.debug');
구성이 배열인 경우, .
을 통해 배열 내부 요소의 값을 가져올 수 있습니다. 예를 들어
config('file.key1.key2');
기본값
config($key, $default);
config는 두 번째 매개변수를 통해 기본값을 전달하며, 구성이 존재하지 않을 경우 기본값을 반환합니다.
구성이 존재하지 않고 기본값이 설정되지 않은 경우 null을 반환합니다.
사용자 정의 구성
개발자는 config/
디렉토리 아래에 자신의 구성 파일을 추가할 수 있습니다. 예를 들어
config/payment.php
<?php
return [
'key' => '...',
'secret' => '...'
];
구성 가져올 때 사용
config('payment');
config('payment.key');
config('payment.key');
구성 변경
webman은 동적으로 구성을 수정하는 것을 지원하지 않으며, 모든 구성은 수동으로 해당 구성 파일을 수정하고 reload 또는 restart를 통해 재시작해야 합니다.
주의
서버 구성config/server.php
및 프로세스 구성config/process.php
는 reload를 지원하지 않으며, restart를 통해서만 적용되어야 합니다.
특별 안내
config
하위 디렉토리에서 구성 파일을 생성하고 읽으려면, 예: config/order/status.php
, config/order
디렉토리 아래에 app.php
파일이 필요하며, 내용은 다음과 같습니다.
<?php
return [
'enable' => true,
];
enable
이 true
라면 프레임워크가 이 디렉토리의 구성을 읽도록 합니다.
최종 구성 파일 디렉토리 구조는 다음과 같습니다.
├── config
│ ├── order
│ │ ├── app.php
│ │ └── status.php
이렇게 하면 config.order.status
를 통해 status.php
에서 반환된 배열 또는 특정 key 데이터를 읽을 수 있습니다.
구성 파일 설명
server.php
return [
'listen' => 'http://0.0.0.0:8787', // 리스닝 포트(1.6.0 버전부터 제거됨, config/process.php에서 구성)
'transport' => 'tcp', // 전송 계층 프로토콜(1.6.0 버전부터 제거됨, config/process.php에서 구성)
'context' => [], // ssl 등 구성(1.6.0 버전부터 제거됨, config/process.php에서 구성)
'name' => 'webman', // 프로세스 이름(1.6.0 버전부터 제거됨, config/process.php에서 구성)
'count' => cpu_count() * 4, // 프로세스 수(1.6.0 버전부터 제거됨, config/process.php에서 구성)
'user' => '', // 사용자(1.6.0 버전부터 제거됨, config/process.php에서 구성)
'group' => '', // 사용자 그룹(1.6.0 버전부터 제거됨, config/process.php에서 구성)
'reusePort' => false, // 포트 재사용 여부(1.6.0 버전부터 제거됨, config/process.php에서 구성)
'event_loop' => '', // 이벤트 루프 클래스, 기본값 자동 선택
'stop_timeout' => 2, // stop/restart/reload 신호를 수신했을 때, 처리 완료를 기다리는 최대 시간, 이 시간을 초과하면 프로세스 강제 종료
'pid_file' => runtime_path() . '/webman.pid', // pid 파일 저장 위치
'status_file' => runtime_path() . '/webman.status', // status 파일 저장 위치
'stdout_file' => runtime_path() . '/logs/stdout.log', // 표준 출력 파일 위치, webman이 시작된 후 모든 출력은 이 파일에 기록됨
'log_file' => runtime_path() . '/logs/workerman.log', // workerman 로그 파일 위치
'max_package_size' => 10 * 1024 * 1024 // 최대 데이터 패킷 크기, 10M. 업로드 파일 크기는 이 제한을 받음
];
app.php
return [
'debug' => true, // debug 모드 활성화 여부, 활성화 시 페이지 오류 발생 시 호출 스택 등 디버그 정보를 출력, 보안상의 이유로 프로덕션 환경에서는 debug를 비활성화해야 함
'error_reporting' => E_ALL, // 오류 보고 수준
'default_timezone' => 'Asia/Shanghai', // 기본 시간대
'public_path' => base_path() . DIRECTORY_SEPARATOR . 'public', // public 디렉토리 위치
'runtime_path' => base_path(false) . DIRECTORY_SEPARATOR . 'runtime', // runtime 디렉토리 위치
'controller_suffix' => 'Controller', // 컨트롤러 접미사
'controller_reuse' => false, // 컨트롤러 재사용 여부
];
process.php
use support\Log;
use support\Request;
use app\process\Http;
global $argv;
return [
// webman 프로세스 구성
'webman' => [
'handler' => Http::class, // 프로세스 처리 클래스
'listen' => 'http://0.0.0.0:8787', // 리스닝 주소
'count' => cpu_count() * 4, // 프로세스 수, 기본적으로 cpu의 4배
'user' => '', // 프로세스 실행 사용자, 낮은 권한의 사용자를 사용해야 함
'group' => '', // 프로세스 실행 사용자 그룹, 낮은 권한의 사용자 그룹을 사용해야 함
'reusePort' => false, // reusePort 활성화 여부, 활성화 시 연결이 서로 다른 worker 프로세스에 고르게 분포됨
'eventLoop' => '', // 이벤트 루프 클래스, 비어있을 경우 server.event_loop 구성 자동 사용
'context' => [], // 리스닝 컨텍스트 구성, 예: ssl
'constructor' => [ // 프로세스 처리 클래스 생성자 매개변수, 본 예에서는 Http 클래스의 생성자 매개변수
'requestClass' => Request::class, // 사용자 정의 요청 클래스 가능
'logger' => Log::channel('default'), // 로그 인스턴스
'appPath' => app_path(), // app 디렉토리 위치
'publicPath' => public_path() // public 디렉토리 위치
]
],
// 모니터 프로세스, 파일 업데이트 자동 로드 및 메모리 누수를 모니터링하는 데 사용
'monitor' => [
'handler' => app\process\Monitor::class, // 처리 클래스
'reloadable' => false, // 현재 프로세스는 reload 실행하지 않음
'constructor' => [ // 프로세스 처리 클래스 생성자 매개변수
// 모니터링할 디렉토리, 너무 많으면 감지가 느려짐
'monitorDir' => array_merge([
app_path(),
config_path(),
base_path() . '/process',
base_path() . '/support',
base_path() . '/resource',
base_path() . '/.env',
], glob(base_path() . '/plugin/*/app'), glob(base_path() . '/plugin/*/config'), glob(base_path() . '/plugin/*/api')),
// 이러한 접미사 파일의 업데이트 감시
'monitorExtensions' => [
'php', 'html', 'htm', 'env'
],
// 기타 옵션
'options' => [
// 파일 모니터링 활성화 여부, 리눅스에서만 유효하며, 기본적으로 데몬 모드에서 파일 모니터링을 활성화하지 않음
'enable_file_monitor' => !in_array('-d', $argv) && DIRECTORY_SEPARATOR === '/',
// 메모리 모니터링 활성화 여부, 리눅스에서만 활성화 지원
'enable_memory_monitor' => DIRECTORY_SEPARATOR === '/',
]
]
]
];
container.php
// psr-11 의존성 주입 컨테이너 인스턴스를 반환
return new Webman\Container;
dependence.php
// 의존성 주입 컨테이너 내의 서비스 및 의존 관계 구성
return [];
route.php
use support\Route;
// /test 경로의 라우트 정의
Route::any('/test', function (Request $request) {
return response('test');
});
view.php
use support\view\Raw;
use support\view\Twig;
use support\view\Blade;
use support\view\ThinkPHP;
return [
'handler' => Raw::class // 기본 뷰 처리 클래스
];
autoload.php
// 프레임워크 자동 로드 파일 구성
return [
'files' => [
base_path() . '/app/functions.php',
base_path() . '/support/Request.php',
base_path() . '/support/Response.php',
]
];
cache.php
// 캐시 구성
return [
'default' => 'file', // 기본 파일
'stores' => [
'file' => [
'driver' => 'file',
'path' => runtime_path('cache') // 캐시 파일 저장 위치
],
'redis' => [
'driver' => 'redis',
'connection' => 'default' // redis 연결명, redis.php의 구성에 해당
],
'array' => [
'driver' => 'array' // 메모리 캐시, 재시작 후 만료
]
]
];
redis.php
return [
'default' => [
'host' => '127.0.0.1',
'password' => null,
'port' => 6379,
'database' => 0,
],
];
database.php
return [
// 기본 데이터베이스
'default' => 'mysql',
// 다양한 데이터베이스 구성
'connections' => [
'mysql' => [
'driver' => 'mysql',
'host' => '127.0.0.1',
'port' => 3306,
'database' => 'webman',
'username' => 'webman',
'password' => '',
'unix_socket' => '',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
'sqlite' => [
'driver' => 'sqlite',
'database' => '',
'prefix' => '',
],
'pgsql' => [
'driver' => 'pgsql',
'host' => '127.0.0.1',
'port' => 5432,
'database' => 'webman',
'username' => 'webman',
'password' => '',
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
'sslmode' => 'prefer',
],
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => 'localhost',
'port' => 1433,
'database' => 'webman',
'username' => 'webman',
'password' => '',
'charset' => 'utf8',
'prefix' => '',
],
],
];
exception.php
return [
// 예외 처리 클래스 설정
'' => support\exception\Handler::class,
];
log.php
return [
'default' => [
'handlers' => [
[
'class' => Monolog\Handler\RotatingFileHandler::class, // 처리기
'constructor' => [
runtime_path() . '/logs/webman.log', // 로그명
7, //$maxFiles // 7일 이내의 로그 보존
Monolog\Logger::DEBUG, // 로그 수준
],
'formatter' => [
'class' => Monolog\Formatter\LineFormatter::class, // 포맷터
'constructor' => [null, 'Y-m-d H:i:s', true], // 포맷팅 매개변수
],
]
],
],
];
session.php
return [
// 유형
'type' => 'file', // or redis or redis_cluster
// 처리기
'handler' => FileSessionHandler::class,
// 구성
'config' => [
'file' => [
'save_path' => runtime_path() . '/sessions', // 저장 디렉토리
],
'redis' => [
'host' => '127.0.0.1',
'port' => 6379,
'auth' => '',
'timeout' => 2,
'database' => '',
'prefix' => 'redis_session_',
],
'redis_cluster' => [
'host' => ['127.0.0.1:7000', '127.0.0.1:7001', '127.0.0.1:7001'],
'timeout' => 2,
'auth' => '',
'prefix' => 'redis_session_',
]
],
'session_name' => 'PHPSID', // session명
'auto_update_timestamp' => false, // 자동으로 타임스탬프 업데이트 여부, 세션 만료 방지
'lifetime' => 7*24*60*60, // 생명주기
'cookie_lifetime' => 365*24*60*60, // cookie 생명주기
'cookie_path' => '/', // cookie 경로
'domain' => '', // cookie 도메인
'http_only' => true, // http 전용 접근
'secure' => false, // https 전용 접근
'same_site' => '', // SameSite 속성
'gc_probability' => [1, 1000], // 세션 수거 확률
];
middleware.php
// 미들웨어 설정
return [];
static.php
return [
'enable' => true, // webman의 정적 파일 접근 활성화 여부
'middleware' => [ // 정적 파일 미들웨어, 캐시 전략, 교차 출처 설정 등
//app\middleware\StaticFile::class,
],
];
translation.php
return [
// 기본 언어
'locale' => 'zh_CN',
// 대체 언어
'fallback_locale' => ['zh_CN', 'en'],
// 언어 파일 저장 위치
'path' => base_path() . '/resource/translations',
];