nervsys / ns
A very slight PHP framework, very easy to use and integrate.
Installs: 10
Dependents: 0
Suggesters: 0
Security: 0
Stars: 94
Watchers: 13
Forks: 42
Type:project
pkg:composer/nervsys/ns
Requires
- php: ^8.1
- ext-curl: *
- ext-fileinfo: *
- ext-gd: *
- ext-gettext: *
- ext-json: *
- ext-libxml: *
- ext-mbstring: *
- ext-openssl: *
- ext-pdo: *
- ext-redis: *
- ext-simplexml: *
This package is auto-updated.
Last update: 2025-12-29 01:26:43 UTC
README
README: English | 简体中文
Overview
Nervsys (derived from "Nerve System") is a minimalist, high-performance PHP framework designed for modern web applications and API development. Inspired by the neural system, the framework aims to process data streams flexibly like nerve cells, helping developers build intelligent application systems based on pure data calls.
🚀 Core Features
- Lightweight Design: Core components are streamlined without redundant dependencies
- Intelligent Routing: Automatic parameter mapping reduces repetitive code
- Dual Mode Support: Supports both Web (CGI) and Command Line (CLI) modes
- Comprehensive Security: Built-in XSS protection, CORS support, API security validation
- Performance Analysis: Built-in performance monitoring and optimization tools
- Concurrent Processing: Supports fibers, multi-process, and Socket communication
- Highly Extensible: Modular design, easy to customize and extend
📋 Requirements
- PHP 8.1 or higher
- Support for both CLI and Web running modes
- Common web servers (Apache/Nginx/IIS) or direct CLI execution
🚦 Quick Start
Installation
-
Clone the framework source code
git clone https://github.com/Jerry-Shaw/Nervsys.git
💡 Tip: One server only needs one set of Nervsys framework to run multiple projects
-
Create project structure
project_root/ ├── api/ # API interface classes │ └── User.php # Example API ├── app/ # Application classes │ ├── Service/ # Business services │ └── Middleware/# Middleware ├── www/ # Web entry directory │ └── index.php # Main entry file └── logs/ # Log directory (auto-created) -
Configure entry file (
www/index.php)<?php require __DIR__ . '/../Nervsys/NS.php'; $ns = new Nervsys\NS(); // Optional configuration (set as needed) $ns->setApiDir('api') // API directory ->setDebugMode(true) // Debug mode (turn off in production) ->setContentType('application/json') // Response type ->assignHook([\app\middleware\Auth::new(), 'check'], '/api/') ->addAutoloadPath(__DIR__ . '/../vendor'); $ns->go();
📖 Usage Guide
Create Your First API
-
Define API class (
api/User.php)<?php namespace api; class User { public function login(string $username, string $password): array { if ($username === 'admin' && $password === '123456') { return [ 'success' => true, 'message' => 'Login successful', 'token' => md5($username . time()) ]; } return ['success' => false, 'message' => 'Invalid username or password']; } public function getProfile(int $userId, string $fields = 'basic'): array { $userData = [ 'id' => $userId, 'name' => 'John Doe', 'email' => 'john@example.com', 'age' => 28 ]; return ['success' => true, 'data' => $userData]; } }
-
Call the API
Web method:
GET /index.php?c=User/login&username=admin&password=123456 POST /index.php Content-Type: application/json { "c": "User/login", "username": "admin", "password": "123456" }
CLI method:
# Parameter call php index.php -c"user/login" -d'username=admin&password=123456' # JSON data php index.php -c"user/login" -d'{"username":"admin","password":"123456"}' # Specify output format php index.php -c"user/getProfile" -d'userId=123' -r"json"
🎯 Quick Start Guide
Nervsys adopts the "Convention Over Configuration" design philosophy, allowing you to skip complex configuration steps and start developing efficiently with intelligent default settings.
📌 Core Principles
-
Centralized Configuration
All framework configuration functions are integrated intoSystem Trait. You don't need to search for configuration options in different files - one-stop configuration management. -
Simplified Initialization
In the entry file, after creating an instance withnew NS(), simply chain-call the configuration methods you need to quickly complete framework initialization. -
Learn as Needed, Progress Gradually
- Beginner: Focus on writing your business APIs without worrying about underlying implementations
- Intermediate user: Learn about specific modules like routing and middleware when needed
- Advanced developer: Explore advanced features like concurrent processing and Socket communication as required
🛠️ Extension Support
- Built-in extension classes: Common functional enhancement classes are pre-built in the
Extdirectory, ready to use out of the box - Extension documentation: Detailed extension class usage manuals are being actively developed - stay tuned!
💡 Development Philosophy: Get it running first, then optimize and adjust as needed. Nervsys is designed to help you start quickly and smoothly transition to advanced features.
🏗️ Core Components
System Configuration (System Trait)
Function: Provides a complete framework configuration interface containing all runtime configuration options. Serves as the core control center of the framework.
Main Configuration Methods:
Path & Directory Configuration:
setRootPath($path)- Set application root directorysetApiDir($dir_name)- Set API directoryaddAutoloadPath($path, $prepend = false)- Add autoload path
Runtime Environment Configuration:
setTimezone($timezone)- Set timezonesetDebugMode($debug_mode)- Set debug modesetLocale($locale)- Set locale/language
Security & CORS Configuration:
addCorsRule($allow_origin, $allow_headers = '', $expose_headers = '')- Add CORS rulesaddXssSkipKeys(...$keys)- Set XSS filter skip keys
Hook System:
assignHook($hook_fn, $target_path, ...$exclude_path)- Register hook functions
Error Handling:
addErrorHandler($handler)- Add error handler
Data I/O Configuration:
readHeaderKeys(...$keys)- Specify HTTP header keys to readreadCookieKeys(...$keys)- Specify cookie keys to readsetContentType($content_type)- Set response content type
Performance Monitoring:
setProfilerThresholds($memory_bytes, $time_milliseconds)- Set performance analysis thresholds
Example:
$ns = new Nervsys\NS('/var/www/myapp', 'api/v2'); $ns->setRootPath('/var/www/app') ->setApiDir('api/v1') ->setDebugMode($_ENV['APP_DEBUG'] ?? false) ->addCorsRule('https://example.com', 'Authorization,Content-Type') ->assignHook([$auth, 'checkToken'], '/api/', '/api/auth/login') ->addAutoloadPath(__DIR__ . '/vendor') ->go();
Application Environment (App Class)
Function: Manages application runtime environment and configuration information, providing a global access point.
Main Methods:
setRoot($root_path)- Set root directorysetApiDir($api_dir)- Set API directorysetLocale($locale)- Set localesetDebugMode($core_debug)- Set debug mode
Environment Information Properties:
$client_ip- Client IP address$user_lang- User language preference$user_agent- User agent$is_cli- Whether in CLI mode$is_https- Whether using HTTPS protocol
Example:
$app = App::new(); echo "Client IP: " . $app->client_ip; echo "Running mode: " . ($app->is_cli ? 'CLI' : 'Web');
Error Handling (Error Class)
Function: Unified error and exception handling system providing graceful error recovery mechanisms.
Main Methods:
saveLog($app, $log_file, $log_content)- Save log fileformatLog($err_lv, $message, $context = [])- Format log contentexceptionHandler($throwable, $report_error = true, $stop_on_error = true)- Exception handler
Error Levels:
- error: Fatal errors (E_ERROR, E_PARSE, etc.)
- warning: Warning errors (E_WARNING, E_USER_WARNING, etc.)
- notice: Notification information (E_NOTICE, E_DEPRECATED, etc.)
Example:
$error = Error::new(); // Add custom error handlers $error->addErrorHandler([$monitor, 'trackError']); $error->addErrorHandler([$notifier, 'sendAlert']); // Record custom log $logContent = $error->formatLog('warning', 'API call frequency too high', [ 'user_id' => 123, 'endpoint' => '/api/user/profile', 'count' => 100 ]); $error->saveLog($app, 'security.log', $logContent);
Hook System (Hook Class)
Function: Provides flexible middleware and pre-processing mechanisms, achieving separation of cross-cutting concerns.
Main Methods:
assign($hook_fn, $target_path, ...$exclude_path)- Register hook functionsrun($full_cmd)- Execute matched hooks
Hook Features:
- Path prefix matching - Precise control over hook scope
- Exclusion path support - Flexible exception configuration
- Automatic parameter injection - Simplifies parameter retrieval for hook functions
- Flow interruption control - Request flow is interrupted when hooks return non-true
Example:
$hook = Hook::new(); // Register authentication hook $hook->assign([$auth, 'checkToken'], '/api/', '/api/auth/login'); // Register logging hook $hook->assign([$logger, 'accessLog'], '/'); // Execute hook if ($hook->run('/api/user/getInfo')) { // Hook check passed, continue processing }
Object Factory (Factory Class)
Function: Provides intelligent object creation and dependency injection, simplifying object lifecycle management.
Main Methods:
new()- Create current class instancegetObj($class_name, $class_args = [], $user_passed = false)- Get object instancebuildArgs($param_reflects, $data_package)- Build parameter array
Features:
- Automatic dependency injection - Automatically resolves and injects constructor dependencies
- Object reuse (Singleton pattern) - Intelligently manages object instances for performance
- Automatic parameter mapping - Automatically matches input data based on parameter names
- Type-safe conversion - Automatically performs type conversion and validation
Example:
class UserService extends \Nervsys\Core\Factory { public function __construct(\Nervsys\Ext\libMySQL $db, int $user_id) { // $db instance automatically injected } } // $db instance automatically injected, and $user_id = 1 passed to constructor $service = UserService::new(['user_id' => 1]);
Routing System (Router Class)
Function: Handles request routing parsing, supporting both Web and command line dual modes with highly flexible routing mechanisms.
Main Methods:
parseCgi($c)- Parse Web request routesparseCli($c)- Parse command line request routesaddCgiRouter($router)- Add Web route processoraddExePathMapping($exe_name, $exe_path)- Add executable file mapping
Routing Features:
- Routing stack mechanism (priority processing) - Supports multi-level route processors
- Custom route processors - Complete control over routing logic
- Executable file mapping - Convenient integration with external tools
- Path normalization - Unified path format processing
Example:
$router = Router::new(); // Custom route processor $router->addCgiRouter(function($path) { if (str_starts_with($path, 'v2/')) { return ['Api\\V2\\' . str_replace('/', '\\', substr($path, 3)), 'handle']; } return []; }); // Add CLI command mapping $router->addExePathMapping('python', '/usr/bin/python3'); // Parse routes $webRoute = $router->parseCgi('user/profile/getInfo'); // ['api\\user\\profile', 'getInfo'] $cliRoute = $router->parseCli('python script.py'); // ['python', '/usr/bin/python3']
Input/Output Processing (IOData Class)
Function: Unified processing of all input/output data, providing consistent data processing interface.
Main Methods:
readCgi()- Read Web request datareadCli()- Read command line parametersgetInputData($keep_headers = false, $keep_cookies = false)- Get processed input dataoutput()- Format output data
Supported Formats:
- Input: JSON, XML, form data, query strings
- Output: JSON, XML, plain text, HTML
Example:
$ioData = IOData::new(); // Configure data reading $ioData->readHeaderKeys('Authorization', 'X-API-Version'); $ioData->readCookieKeys('session_token'); // Read Web request $ioData->readCgi(); // Get processed data $inputData = $ioData->getInputData(true, true); // Set output $ioData->src_output = ['success' => true, 'data' => $result]; $ioData->setContentType('application/json'); // Output response $ioData->output();
Security Protection (Security Class)
Function: Provides comprehensive security protection features to ensure application data security.
Main Methods:
getApiResource($class_name, $method_name, $class_args = [], $filter = null)- Validate API resourcesantiXss($data)- XSS attack protection
Security Features:
- API resource security validation - Ensures only legitimate APIs can be called
- Automatic XSS filtering - Intelligent protection against cross-site scripting attacks
- Framework core class protection - Prevents malicious calls to framework core components
Example:
$security = Security::new(); // Configure XSS filter skip keys $security->addXssSkipKeys('html_content', 'raw_data', 'code_block'); // Execute XSS protection $safeData = $security->antiXss($_POST);
Reflection Management (Reflect Class)
Function: Provides efficient reflection information cache management, significantly improving reflection operation performance.
Main Methods:
getClass($class_name)- Get class reflection informationgetMethod($class_name, $method_name)- Get method reflection informationgetMethods($class_name, $filter = null)- Get all class methods
Performance Optimization:
- Intelligent caching of reflection objects - Avoids repeated reflection operation overhead
- Reduced duplicate reflection operations - Improves overall framework performance
- Batch retrieval support - Retrieves multiple reflection information at once
Example:
// Get class method information $methods = Reflect::getMethods('App\Controller\UserController', \ReflectionMethod::IS_PUBLIC); // Get parameter information $method = Reflect::getMethod('UserService', 'createUser'); $params = $method->getParameters(); foreach ($params as $param) { $info = Reflect::getParameterInfo($param); // $info contains name, type, default value, etc. }
Cross-Origin Processing (CORS Class)
Function: Handles cross-origin requests and security configuration, simplifying CORS setup.
Main Methods:
addRule($allowed_origin, $allowed_headers = '', $exposed_headers = '')- Add cross-origin rulescheckPermission($is_https)- Check and process cross-origin requests
Supported Features:
- Multiple domain configuration - Supports access from multiple origins
- Custom request headers - Flexible control over request header permissions
- Preflight request handling - Automatically processes OPTIONS preflight requests
- Security validation - Ensures cross-origin request safety
Example:
$cors = CORS::new(); $cors->addRule('https://example.com', 'Authorization,Content-Type,X-API-Key') ->addRule('http://localhost:3000', 'Content-Type') ->addRule('*'); // Allow all origins (use with caution) // Call before request processing $cors->checkPermission($app->is_https);
Method Caller (Caller Class)
Function: Safely executes API methods and external programs, providing unified calling interface.
Main Methods:
runApiFn($cmd, $api_args, $anti_xss)- Execute API method callsrunProgram($cmd_pair, $cmd_argv = [], $cwd_path = '', $realtime_debug = false)- Execute external programs
Security Features:
- Automatic XSS protection - Built-in security protection mechanism
- API resource validation - Ensures call legitimacy
- Exception-safe handling - Graceful handling of call exceptions
Example:
$caller = Caller::new(); // Execute API method $result = $caller->runApiFn( ['App\Controller\UserController', 'getProfile'], ['userId' => 123, 'fields' => 'all'], true // Enable XSS protection ); // Execute system command $output = $caller->runProgram( ['ls', '/usr/bin/ls'], ['-la', '/var/log'], '/tmp', false );
Performance Analysis (Profiler Class)
Function: Code performance monitoring and analysis, helping identify performance bottlenecks.
Main Methods:
setThresholds($memory_bytes, $time_milliseconds)- Set performance thresholdsstart($profile_name, $analyze_cli = false)- Start performance analysisend($profile_name, $force_save = false, $with_input_data = false, $log_file_name = 'profiler')- End performance analysis
Monitoring Metrics:
- Execution time - Millisecond-precision execution time monitoring
- Memory usage - Real-time memory usage tracking
- Call counts - Statistics on code block call frequency
- Threshold warnings - Automatic detection of performance bottlenecks
Example:
$profiler = Profiler::new(); // Set thresholds: 1MB memory, 100ms time $profiler->setThresholds(1024 * 1024, 100); // Monitor database query $profiler->start('database_query'); $result = $db->query('SELECT * FROM users WHERE active = 1'); $profiler->end('database_query'); // Detailed logs are automatically recorded if thresholds are exceeded // Log content: time, memory, parameters, etc., for performance tuning
Operating System Management (OSMgr Class)
Function: Cross-platform operating system functionality encapsulation, providing unified system operation interface.
Main Methods:
getIPv4()- Get local IPv4 addressesgetIPv6()- Get local IPv6 addressesgetHwHash()- Get hardware hash identifiergetPhpPath()- Get PHP executable pathbuildCmd($command)- Build system commands
Cross-Platform Support:
- Windows (WINNT)
- Linux
- macOS (Darwin)
Example:
$osMgr = OSMgr::new(); // Get system information $ipv4Addresses = $osMgr->getIPv4(); $hardwareHash = $osMgr->getHwHash(); $phpPath = $osMgr->getPhpPath(); // Build background command $command = $osMgr->inBackground(true)->buildCmd('php worker.php'); // Execute system command exec($command);
Process Manager (ProcMgr Class)
Function: Multi-process management and inter-process communication, supporting high-concurrency task processing.
Main Methods:
command($command)- Set command to executerunMP($run_proc = 8, $max_executions = 2000)- Run multi-process poolputJob($job_argv, $stdout_callback = null, $stderr_callback = null)- Submit tasksawaitJobs()- Wait for all tasks to complete
Process Features:
- Process pool load balancing - Intelligent task distribution to idle processes
- Task queue management - Ordered processing of large task volumes
- Inter-process communication - Supports data exchange between processes
- Error recovery mechanism - Automatic handling of process exceptions
Example:
$procMgr = ProcMgr::new(); // Start 4 worker processes $procMgr->command(['php', 'worker.php']) ->runMP(4, 1000); // Submit batch tasks for ($i = 0; $i < 100; $i++) { $procMgr->putJob( json_encode(['task_id' => $i, 'data' => 'task_' . $i]), function($output) use ($i) { echo "Task {$i} completed: {$output}\n"; } ); } // Wait for all tasks to complete $procMgr->awaitJobs();
Fiber Manager (FiberMgr Class)
Function: PHP fiber (coroutine) management, implementing lightweight concurrent processing.
Main Methods:
await($callable, $arguments = [])- Create and start fibersasync($callable, $arguments = [], $callback = null)- Add asynchronous taskscommit()- Submit and execute all asynchronous tasks
Fiber Features:
- Lightweight concurrency - Extremely low memory overhead
- Cooperative scheduling - Fibers voluntarily yield execution
- Low memory overhead - Much lighter than threads and processes
- Single-threaded concurrency - Achieves concurrency effects within a single thread
Example:
$fiberMgr = FiberMgr::new(); // Add asynchronous task $fiberMgr->async( function($userId) { Fiber::suspend(); // Suspend fiber return fetchUserData($userId); }, ['userId' => 123], function($result) { echo "User data: " . json_encode($result) . "\n"; } ); // Submit and execute all tasks $fiberMgr->commit();
Socket Manager (SocketMgr Class)
Function: Socket communication and WebSocket support, building real-time communication applications.
Main Methods:
listenTo($address, $websocket = false)- Start server listeningconnectTo($address)- Connect to serversetDebugMode($debug_mode)- Set debug modeonConnect($callback)- Connection event listeneronMessage($callback)- Message event listenersendMessage($socket_id, $message)- Send messages
Protocol Support:
- TCP - Reliable byte stream transmission
- UDP - Connectionless datagram transmission
- WebSocket - Full-duplex communication protocol
- SSL/TLS - Secure encrypted transmission
Example:
$socketMgr = SocketMgr::new(); // Configure WebSocket server $socketMgr->setDebugMode(true) ->onConnect(function($socketId) { echo "Client {$socketId} connected\n"; }) ->onMessage(function($socketId, $message) use ($socketMgr) { echo "Message received: {$message}\n"; // Process message and reply $socketMgr->sendMessage($socketId, "Received: {$message}"); }); // Start WebSocket server $socketMgr->listenTo('tcp://0.0.0.0:8080', true);
🔧 Advanced Features
Process Management (ProcMgr Class)
Multi-process task processing, suitable for batch data processing and high-concurrency scenarios.
$procMgr = ProcMgr::new() ->command(['php', 'worker.php']) ->runMP(4); // Start 4 worker processes // Submit tasks for ($i = 0; $i < 100; $i++) { $procMgr->putJob( json_encode(['task_id' => $i]), function($output) use ($i) { echo "Task {$i} completed: {$output}\n"; } ); } $procMgr->awaitJobs();
WebSocket Communication (SocketMgr Class)
Real-time communication support, easily building chat applications, real-time notifications, etc.
$socketMgr = SocketMgr::new() ->setDebugMode(true) ->onConnect(function($socketId) { echo "Client {$socketId} connected\n"; }) ->onMessage(function($socketId, $message) use ($socketMgr) { $socketMgr->sendMessage($socketId, "Received: {$message}"); }) ->listenTo('tcp://0.0.0.0:8080', true);
Performance Analysis (Profiler Class)
Code performance monitoring to help optimize application performance.
$profiler = Profiler::new(); $profiler->setThresholds(1024 * 1024, 100); // 1MB memory, 100ms time $profiler->start('database_query'); $result = $db->query('SELECT * FROM users'); $profiler->end('database_query'); // Auto-log when thresholds exceeded
Middleware System
Implement flexible middleware mechanism through hook system, handling cross-cutting concerns like authentication, logging, etc.
// Create authentication middleware class AuthMiddleware { public function checkToken($token): bool { return $this->validateToken($token); } } // Register middleware $ns->assignHook([new AuthMiddleware(), 'checkToken'], '/api/', '/api/auth/login');
Custom Routing
Extend default routing mechanism to implement advanced routing features like RESTful routing.
// Custom route processor $router->addCgiRouter(function($path) { if (preg_match('/^api\/(v[0-9]+)\/([a-z]+)\/([0-9]+)$/', $path, $matches)) { $version = $matches[1]; $resource = ucfirst($matches[2]); $id = $matches[3]; return ["Api\\{$version}\\{$resource}Controller", 'show']; } return []; });
Real-time Communication Application
Build complete real-time chat server, showcasing SocketMgr's powerful capabilities.
// Real-time chat server $socketMgr = SocketMgr::new(); $connectedUsers = []; $socketMgr->onConnect(function($socketId) use (&$connectedUsers) { $connectedUsers[$socketId] = ['id' => $socketId, 'connected_at' => time()]; }); $socketMgr->onMessage(function($socketId, $message) use ($socketMgr, &$connectedUsers) { $data = json_decode($message, true); if ($data['type'] === 'chat') { foreach ($connectedUsers as $user) { $socketMgr->sendMessage($user['id'], json_encode([ 'type' => 'message', 'from' => $socketId, 'content' => $data['content'], 'time' => date('H:i:s') ])); } } }); $socketMgr->listenTo('tcp://0.0.0.0:8080', true);
📁 Project Structure Recommendation
project/
├── api/ # API interface layer
│ ├── v1/ # Version 1
│ └── v2/ # Version 2
├── app/ # Application layer
│ ├── Service/ # Business services
│ ├── Model/ # Data models
│ └── Middleware/ # Middleware
├── config/ # Configuration files
├── logs/ # Logs
├── public/ # Web entry
│ └── index.php
└── vendor/ # Dependencies
Environment Configuration Management
Manage different environment configurations through environment variables, achieving configuration-code separation.
// config/environment.php return [ 'development' => [ 'debug' => true, 'database' => [ 'host' => 'localhost', 'name' => 'app_dev' ] ], 'production' => [ 'debug' => false, 'database' => [ 'host' => 'db.server.com', 'name' => 'app_prod' ] ] ]; // Entry file configuration $env = $_SERVER['APP_ENV'] ?? 'development'; $config = require __DIR__ . '/../config/environment.php'; $ns = new Nervsys\NS(); $ns->setDebugMode($config[$env]['debug']); // ... other configurations
Error Monitoring and Logging
Implement custom error handlers for more friendly error information and comprehensive logging.
// Custom error handler class CustomErrorHandler { public function handle(App $app, IOData $ioData, Throwable $e, bool $report): void { // Record detailed error information $this->logger->error($e->getMessage(), [ 'file' => $e->getFile(), 'line' => $e->getLine(), 'trace' => $e->getTraceAsString(), 'request' => [ 'command' => $ioData->src_cmd, 'input' => $ioData->src_input, 'client_ip' => $app->client_ip ] ]); // Return generic error in production if (!$app->debug_mode) { $ioData->src_msg = [ 'code' => 500, 'message' => 'System busy, please try again later', 'request_id' => uniqid() ]; } } } // Register error handler $error->addErrorHandler([new CustomErrorHandler(), 'handle']);
❓ Frequently Asked Questions
Q: How to upgrade the framework?
A: Simply replace the framework files. Nervsys uses stateless design, making upgrades simple and safe. We recommend backing up your project code before upgrading, just in case.
Q: Does it support PHP 8.2/8.3/8.4/8.5?
A: Fully supports all versions from PHP 8.1+, including the latest PHP 8.5. The framework continuously follows PHP's latest features.
Q: How to handle database operations?
A: The framework includes two database processing solutions:
- General solution:
Ext\libPDO- Supports MySQL, MSSQL, PostgreSQL, Oracle and more, providing standard PDO interface - MySQL-specific:
Ext\libMySQL- Provides more convenient MySQL operation interface with encapsulated common operations
Q: How to integrate third-party libraries (like Composer packages)?
A: Use the addAutoloadPath() method to add Composer's vendor directory:
$ns->addAutoloadPath(__DIR__ . '/../vendor');
Q: How to configure for production environment?
A:
- Debug mode: Make sure to turn off debug mode (
setDebugMode(false)) - Error handling: Configure appropriate error handlers to avoid sensitive information leaks
- File permissions: Set correct file permissions (logs directory needs write access)
- Server configuration: Deploy like any regular PHP project, supports common servers like Nginx/Apache
- Security recommendations: Enable HTTPS, configure appropriate CORS rules
Q: What about framework performance?
A: Nervsys is designed for high performance:
- Minimalist core: Core files only hundreds of KB, reducing unnecessary overhead
- Fast startup: Optimized initialization process, rapid response
- Memory-friendly: Streamlined code structure and efficient memory management
- High concurrency support: Built-in multi-process and fiber support, suitable for high-concurrency scenarios
Q: How should beginners get started?
A: We recommend following this learning path:
- Step 1 (5 minutes): Configure entry file with
new NS()and basic settings - Step 2 (15 minutes): Write your first API class and test it
- Step 3 (as needed): Add routing, middleware and other features based on project requirements
- Step 4 (advanced): Consult corresponding module documentation when advanced features are needed
Key advice: No need to deeply understand all modules from the start. Nervsys is designed to help you start quickly and gradually master more features through actual development.
🤝 Contribution Guidelines
We welcome and appreciate all forms of contributions! Whether reporting bugs, suggesting improvements, or submitting code, all help make Nervsys better.
Contribution Process
- Fork repository: Click the Fork button in the top-right of GitHub
- Create branch:
git checkout -b feature/your-feature-name - Commit changes:
git commit -m 'Add some amazing feature' - Push branch:
git push origin feature/your-feature-name - Create PR: Create a Pull Request on GitHub describing your changes
Development Standards
- Follow PSR coding standards
- Add appropriate comments and documentation
- Ensure code compatibility with PHP 8.1+
- Provide usage examples for functional changes
📄 License
Nervsys uses the Apache License 2.0 open source license.
View the complete license content: LICENSE.md
Main Terms:
- ✅ Allows commercial use, modification, distribution
- ✅ Requires preservation of copyright and license notices
- ⚠️ Does not provide patent grant
- ⚠️ No warranty of merchantability or fitness for purpose
📞 Support & Feedback
Get Help
- 📚 Documentation: This README is the main documentation containing complete framework usage guide
- 🐛 Issue reporting: GitHub Issues
- 💬 Technical discussion: Welcome to start technical discussions in Issues
Contact Author
- 📧 Email: jerry-shaw@live.com
- ⭐ Star support: If you like the framework, welcome to give a Star to support project development!
Version Updates
- 🔔 Follow Releases: Get latest versions and update announcements
- 📝 Changelog: Important changes are detailed in Releases
Nervsys - Process data streams intelligently like the nervous system, building efficient PHP applications.