Configuration Files
Location
The configuration files for Webman are located in the config/
directory. You can access the corresponding configuration in your project using the config()
function.
Accessing Configuration
Get all configurations
config();
Get all configurations from config/app.php
config('app');
Get the debug
configuration from config/app.php
config('app.debug');
If the configuration is an array, you can access the internal element values using .
, for example
config('file.key1.key2');
Default Value
config($key, $default);
The config
function allows you to pass a default value as the second parameter. If the configuration does not exist, it will return the default value. If the configuration does not exist and no default value is set, it will return null.
Custom Configuration
Developers can add their own configuration files in the config/
directory, for example
config/payment.php
<?php
return [
'key' => '...',
'secret' => '...'
];
Accessing Configuration
config('payment');
config('payment.key');
Modifying Configurations
Webman does not support dynamically modifying configurations; all configurations must be manually changed in the corresponding configuration files, followed by a reload or restart.
Note
The server configuration inconfig/server.php
and the process configuration inconfig/process.php
do not support reload and need a restart to take effect.
Special Reminder
If you want to create a configuration file in a subdirectory under config
and read it, for example: config/order/status.php
, then there needs to be an app.php
file in the config/order
directory with the following contents
<?php
return [
'enable' => true,
];
The enable
set to true
means allowing the framework to read the configuration from this directory.
The final directory tree of configuration files will look like this
├── config
│ ├── order
│ │ ├── app.php
│ │ └── status.php
This way you can read the array or specific key data returned in status.php
using config.order.status
.
Explanation of Configuration Files
server.php
return [
'listen' => 'http://0.0.0.0:8787', // Listening port (removed since version 1.6.0, configured in config/process.php)
'transport' => 'tcp', // Transport layer protocol (removed since version 1.6.0, configured in config/process.php)
'context' => [], // SSL and other configurations (removed since version 1.6.0, configured in config/process.php)
'name' => 'webman', // Process name (removed since version 1.6.0, configured in config/process.php)
'count' => cpu_count() * 4, // Number of processes (removed since version 1.6.0, configured in config/process.php)
'user' => '', // User (removed since version 1.6.0, configured in config/process.php)
'group' => '', // User group (removed since version 1.6.0, configured in config/process.php)
'reusePort' => false, // Whether to enable port reuse (removed since version 1.6.0, configured in config/process.php)
'event_loop' => '', // Event loop class, defaults to automatic selection
'stop_timeout' => 2, // Maximum time to wait for processing to complete when receiving stop/restart/reload signal, exceeding this time will forcefully exit the process
'pid_file' => runtime_path() . '/webman.pid', // Location to store PID file
'status_file' => runtime_path() . '/webman.status', // Location to store status file
'stdout_file' => runtime_path() . '/logs/stdout.log', // Location of standard output file, all outputs after webman is started will be written here
'log_file' => runtime_path() . '/logs/workerman.log', // Location of workerman log file
'max_package_size' => 10 * 1024 * 1024 // Maximum packet size, 10M. The size of uploaded files is limited by this
];
app.php
return [
'debug' => true, // Whether to enable debug mode, when enabled, page errors will output call stack and other debugging information, should be turned off in production for security
'error_reporting' => E_ALL, // Error reporting level
'default_timezone' => 'Asia/Shanghai', // Default timezone
'public_path' => base_path() . DIRECTORY_SEPARATOR . 'public', // Public directory location
'runtime_path' => base_path(false) . DIRECTORY_SEPARATOR . 'runtime', // Runtime directory location
'controller_suffix' => 'Controller', // Controller suffix
'controller_reuse' => false, // Whether to reuse controllers
];
process.php
use support\Log;
use support\Request;
use app\process\Http;
global $argv;
return [
// Webman process configuration
'webman' => [
'handler' => Http::class, // Process handler class
'listen' => 'http://0.0.0.0:8787', // Listening address
'count' => cpu_count() * 4, // Number of processes, default is 4 times the CPU count
'user' => '', // User under which the process runs, should be a lower privilege user
'group' => '', // User group under which the process runs, should be a lower privilege group
'reusePort' => false, // Whether to enable reusePort, when enabled, connections will be evenly distributed to different worker processes
'eventLoop' => '', // Event loop class, automatically uses server.event_loop configuration if empty
'context' => [], // Listening context configuration, e.g., SSL
'constructor' => [ // Constructor parameters for the process handler class, in this example it is the Http class constructor parameters
'requestClass' => Request::class, // Customizable request class
'logger' => Log::channel('default'), // Log instance
'appPath' => app_path(), // Application directory location
'publicPath' => public_path() // Public directory location
]
],
// Monitoring process, used for detecting file updates for auto-loading and memory leaks
'monitor' => [
'handler' => app\process\Monitor::class, // Handler class
'reloadable' => false, // The current process does not perform reload
'constructor' => [ // Constructor parameters for the process handler class
// Listening directories, avoid excessive, as this will slow down detection
'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')),
// Monitor updates for these file extensions
'monitorExtensions' => [
'php', 'html', 'htm', 'env'
],
// Other options
'options' => [
// Whether to enable file monitoring; only effective on Linux. File monitoring is not enabled by default in daemon mode
'enable_file_monitor' => !in_array('-d', $argv) && DIRECTORY_SEPARATOR === '/',
// Whether to enable memory monitoring; only supporting enabling in Linux
'enable_memory_monitor' => DIRECTORY_SEPARATOR === '/',
]
]
]
];
container.php
// Return a psr-11 dependency injection container instance
return new Webman\Container;
dependence.php
// Used to configure services and dependencies in the dependency injection container
return [];
route.php
use support\Route;
// Define route for /test path
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 // Default view handling class
];
autoload.php
// Configure files for automatic loading by the framework
return [
'files' => [
base_path() . '/app/functions.php',
base_path() . '/support/Request.php',
base_path() . '/support/Response.php',
]
];
cache.php
// Cache configuration
return [
'default' => 'file', // Default is file
'stores' => [
'file' => [
'driver' => 'file',
'path' => runtime_path('cache') // Location for storing cache files
],
'redis' => [
'driver' => 'redis',
'connection' => 'default' // Redis connection name, corresponding to configuration in redis.php
],
'array' => [
'driver' => 'array' // In-memory cache, lost after restart
]
]
];
redis.php
return [
'default' => [
'host' => '127.0.0.1',
'password' => null,
'port' => 6379,
'database' => 0,
],
];
database.php
return [
// Default database
'default' => 'mysql',
// Various database configurations
'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 [
// Set the exception handling class
'' => support\exception\Handler::class,
];
log.php
return [
'default' => [
'handlers' => [
[
'class' => Monolog\Handler\RotatingFileHandler::class, // Handler
'constructor' => [
runtime_path() . '/logs/webman.log', // Log name
7, //$maxFiles // Keep logs from the last 7 days
Monolog\Logger::DEBUG, // Log level
],
'formatter' => [
'class' => Monolog\Formatter\LineFormatter::class, // Formatter
'constructor' => [null, 'Y-m-d H:i:s', true], // Formatter parameters
],
]
],
],
];
session.php
return [
// Type
'type' => 'file', // or redis or redis_cluster
// Handler
'handler' => FileSessionHandler::class,
// Configuration
'config' => [
'file' => [
'save_path' => runtime_path() . '/sessions', // Storage directory
],
'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 name
'auto_update_timestamp' => false, // Whether to automatically update timestamp to prevent session expiration
'lifetime' => 7*24*60*60, // Lifetime
'cookie_lifetime' => 365*24*60*60, // Cookie lifetime
'cookie_path' => '/', // Cookie path
'domain' => '', // Cookie domain
'http_only' => true, // HTTP access only
'secure' => false, // HTTPS access only
'same_site' => '', // SameSite attribute
'gc_probability' => [1, 1000], // Session garbage collection probability
];
middleware.php
// Set middleware
return [];
static.php
return [
'enable' => true, // Whether to enable static file access in webman
'middleware' => [ // Middleware for static files, can be used to set cache strategies, CORS, etc.
//app\middleware\StaticFile::class,
],
];
translation.php
return [
// Default language
'locale' => 'zh_CN',
// Fallback language
'fallback_locale' => ['zh_CN', 'en'],
// Language file storage location
'path' => base_path() . '/resource/translations',
];