### Install and Start Adapterman with Composer (Shell) Source: https://github.com/joanhey/adapterman/blob/master/recipes/thinkphp.md Use Composer to add Adapterman as a project dependency and then execute the provided script to start the Adapterman server. The start script internally runs a PHP command with a specific configuration and entry point. ```Shell composer require joanhey/adapterman ./vendor/bin/adapterman start ``` -------------------------------- ### Starting Adapterman Workerman Server in Shell Source: https://github.com/joanhey/adapterman/blob/master/recipes/laravel.md This shell command starts the Adapterman/Workerman server defined in `server.php`. The `start` argument typically tells Workerman to run the workers in the foreground or background, depending on the script's implementation. ```shell php server.php start ``` -------------------------------- ### Running the Workerman Server - Shell Source: https://github.com/joanhey/adapterman/blob/master/recipes/slim.md Command line instruction to start the Workerman server, executing the modified `start.php` file. ```Shell php server.php start ``` -------------------------------- ### Initializing Adapterman and Workerman Server in PHP Source: https://github.com/joanhey/adapterman/blob/master/recipes/laravel.md This PHP script sets up a Workerman HTTP server integrated with Adapterman. It initializes Adapterman, creates a Worker instance listening on a specified address and port, configures worker count and name, and defines event handlers for worker start and message reception. The `onWorkerStart` handler includes the application's entry point (`start.php`), and the `onMessage` handler processes incoming requests by calling the `run()` function defined in `start.php`. ```php count = cpu_count(); // or any positive integer $http_worker->name = env('APP_NAME'); // or any string $http_worker->onWorkerStart = static function () { require __DIR__.'/start.php'; }; $http_worker->onMessage = static function ($connection, $request) { $connection->send(run()); }; Worker::runAll(); ``` -------------------------------- ### Starting Workerman Server Source: https://github.com/joanhey/adapterman/blob/master/recipes/bolt.md Command executed in the terminal to start the Workerman server using the provided `server.php` script, which would typically integrate with the modified `start.php`. ```shell php server.php start ``` -------------------------------- ### Initialize and Run Lumen Application in PHP Source: https://github.com/joanhey/adapterman/blob/master/recipes/lumen.md This PHP snippet initializes the Lumen application by requiring the bootstrap file and defines a `run` function. The `run` function captures the output buffer while executing the application's main run method, returning the captured output. ```php run();\n\n return ob_get_clean();\n}\n\n ``` -------------------------------- ### Starting Workerman with Custom php.ini (Bash) Source: https://github.com/joanhey/adapterman/blob/master/README.md Command to start the Workerman server using a specific PHP configuration file (`cli-php.ini`) instead of the default system-wide or user-specific configuration. ```bash php -c cli-php.ini server.php start ``` -------------------------------- ### Modified Laravel Entry Point for Adapterman in PHP Source: https://github.com/joanhey/adapterman/blob/master/recipes/laravel.md This modified version of the Laravel entry point (`start.php`) is designed to be included by the Adapterman/Workerman server. It loads the application and resolves the HTTP kernel, storing the kernel instance globally. It defines a `run()` function that captures output buffering, handles the request using the global kernel, sends the response, terminates the kernel, and returns the buffered output. This function is called by the Workerman `onMessage` handler. ```php make(Illuminate\Contracts\Http\Kernel::class); function run() { global $kernel; ob_start(); $response = $kernel->handle( $request = Illuminate\Http\Request::capture() ); $response->send(); $kernel->terminate($request, $response); return ob_get_clean(); } ``` -------------------------------- ### Slim App Setup with Global Variable - PHP Source: https://github.com/joanhey/adapterman/blob/master/recipes/slim.md Initializes the Slim application using `AppFactory` and a DI container, ensuring the `$app` variable is declared as global for access within the adapted run function. ```PHP use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; use Slim\Factory\AppFactory; global $app; // workerman AppFactory::setContainer(new \DI\Container()); $app = AppFactory::create(); ``` -------------------------------- ### Original Laravel Public Index Entry Point in PHP Source: https://github.com/joanhey/adapterman/blob/master/recipes/laravel.md This snippet shows the standard entry point (`./public/index.php`) for a Laravel application. It loads the application instance, resolves the HTTP kernel, handles the incoming request, sends the response, and terminates the kernel. This code is intended to be replaced when adapting the application for Adapterman/Workerman. ```php make(Illuminate\Contracts\Http\Kernel::class); $response = $kernel->handle( $request = Illuminate\Http\Request::capture() ); $response->send(); $kernel->terminate($request, $response); ``` -------------------------------- ### Caddyfile Configuration for Static Files and Proxying Source: https://github.com/joanhey/adapterman/blob/master/recipes/caddy-config.md This Caddyfile configuration block defines the behavior for a specific domain. It enables Zstandard and Gzip encoding, sets the document root for static files, enables the file server, and proxies all other requests to a backend running on localhost:8080. ```Caddyfile your.domain.com { encode zstd gzip root * /path/to/public file_server reverse_proxy localhost:8080 } ``` -------------------------------- ### Install Adapterman via Composer Shell Source: https://github.com/joanhey/adapterman/blob/master/README.md This command installs the Adapterman library and its dependency Workerman using the Composer package manager. It's the standard way to add Adapterman to a PHP project. ```Shell composer require joanhey/adapterman ``` -------------------------------- ### Workerman Server Management Commands (Bash) Source: https://github.com/joanhey/adapterman/blob/master/README.md Common command-line interface commands for managing a Workerman server, including starting, stopping, checking status, and reloading the server process. ```bash php server.php start ``` ```bash php server.php start -d ``` ```bash php server.php status ``` ```bash php server.php status -d ``` ```bash php server.php connections ``` ```bash php server.php stop ``` ```bash php server.php stop -g ``` ```bash php server.php restart ``` ```bash php server.php reload ``` ```bash php server.php reload -g ``` -------------------------------- ### Access Application in Browser (HTTP) Source: https://github.com/joanhey/adapterman/blob/master/recipes/thinkphp.md After starting the Adapterman server, access your ThinkPHP application by navigating to this URL in a web browser. The default port is 8080. ```HTTP http://localhost:8080 ``` -------------------------------- ### Running Pestphp HTTP Tests (Shell) Source: https://github.com/joanhey/adapterman/blob/master/tests/README.md Execute this shell command from the project's root directory to initiate the feature tests using the Pestphp test runner. Ensure you have PHP 8.1 or greater and the curl extension installed as prerequisites. ```sh vendor/bin/pest ``` -------------------------------- ### Original Bolt CMS Entry Point (index.php) Source: https://github.com/joanhey/adapterman/blob/master/recipes/bolt.md The standard entry point for a Bolt CMS application. It handles environment setup, debugging, trusted proxies/hosts, creates a kernel and request object, processes the request, sends the response, and terminates the kernel. ```php bootEnv(dirname(__DIR__) . '/.env'); if ($_SERVER['APP_DEBUG']) { umask(0000); Debug::enable(); } if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? false) { Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST); } if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? false) { Request::setTrustedHosts([$trustedHosts]); } $kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']); $request = Request::createFromGlobals(); $response = $kernel->handle($request); $response->send(); $kernel->terminate($request, $response); ``` -------------------------------- ### Nginx Configuration for Workerman Proxy Source: https://github.com/joanhey/adapterman/blob/master/recipes/nginx-config.md This Nginx server block configures a virtual host to listen on port 80, serve static files from a specified root directory, and proxy requests that don't map to static files to a backend Workerman application running on `127.0.0.1:8080`. ```nginx server { listen 80 default_server; listen [::]:80 default_server ipv6only=on; # Change to your public dir root /var/www/html/your-app/public; index index.html index.htm; server_name localhost; location / { try_files $uri $uri/ @backend; } # Add the ip:port of your app location @backend { proxy_pass 127.0.0.1:8080; // or localhost:8080; proxy_http_version 1.1; proxy_set_header Connection ""; } location ~ /\. { deny all; } } ``` -------------------------------- ### Modified Drupal Entry Point for Workerman (start.php) Source: https://github.com/joanhey/adapterman/blob/master/recipes/drupal.md The modified Drupal entry point for use with Workerman. It makes the Drupal kernel global and wraps the request handling logic within a `run()` function, capturing output buffering, suitable for integration into a Workerman worker process. ```php handle($request); $response->send(); $kernel->terminate($request, $response); return ob_get_clean(); } ``` -------------------------------- ### Original Drupal Entry Point (index.php) Source: https://github.com/joanhey/adapterman/blob/master/recipes/drupal.md The standard Drupal index.php file, serving all page requests by initializing the kernel, handling the request, sending the response, and terminating the kernel. ```php handle($request); $response->send(); $kernel->terminate($request, $response); ``` -------------------------------- ### Workerman Server Configuration (server.php) PHP Source: https://github.com/joanhey/adapterman/blob/master/README.md This PHP script sets up the Workerman HTTP worker. It initializes Adapterman, configures the worker's address, port, process count, and name, and defines the `onWorkerStart` and `onMessage` callbacks to handle requests by including and running the application's `start.php`. ```PHP count = 8; $http_worker->name = 'AdapterMan'; $http_worker->onWorkerStart = static function () { //init(); require __DIR__.'/start.php'; }; $http_worker->onMessage = static function ($connection, $request) { $connection->send(run()); }; Worker::runAll(); ``` -------------------------------- ### Original Slim Run Method (To Be Changed) - PHP Source: https://github.com/joanhey/adapterman/blob/master/recipes/slim.md Shows the standard way a Slim application is run, which needs modification for Workerman integration. ```PHP $app->run(); ``` -------------------------------- ### Adapting Slim Run Method for Workerman - PHP Source: https://github.com/joanhey/adapterman/blob/master/recipes/slim.md Defines a new `run` function that buffers output, allowing the Slim application to execute within the Workerman event loop structure. Requires the `$app` variable to be globally accessible. ```PHP function run(): string { global $app; ob_start(); $app->run(); return ob_get_clean(); } ``` -------------------------------- ### Original Symfony Kernel Handling - PHP Source: https://github.com/joanhey/adapterman/blob/master/recipes/symfony.md This snippet shows the standard Symfony kernel handling process typically found in the `index.php` file. It initializes the kernel, creates a request from global variables, handles the request, sends the response, and terminates the kernel. ```php $kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']); $request = Request::createFromGlobals(); $response = $kernel->handle($request); $response->send(); $kernel->terminate($request, $response); ``` -------------------------------- ### Modified Bolt CMS Entry Point for Workerman (start.php) Source: https://github.com/joanhey/adapterman/blob/master/recipes/bolt.md The modified entry point designed to run within a Workerman context. It comments out direct PHP ini modifications, makes the kernel a global variable, and wraps the request handling logic within a `run()` function that uses output buffering to capture the response. ```php bootEnv(dirname(__DIR__) . '/.env'); if ($_SERVER['APP_DEBUG']) { umask(0000); Debug::enable(); } if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? false) { Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST); } if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? false) { Request::setTrustedHosts([$trustedHosts]); } global $kernel; $kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']); function run(): string { global $kernel; ob_start(); $request = Request::createFromGlobals(); $response = $kernel->handle($request); $response->send(); $kernel->terminate($request, $response); return ob_get_clean(); } ``` -------------------------------- ### Accessing the Application - HTTP Source: https://github.com/joanhey/adapterman/blob/master/recipes/slim.md The default URL to access the application running on the Workerman server in a web browser. ```HTTP http://localhost:8080 ``` -------------------------------- ### Modified Symfony Kernel Handling for Workerman - PHP Source: https://github.com/joanhey/adapterman/blob/master/recipes/symfony.md This modified snippet adapts the Symfony kernel handling for use with Workerman. It declares the kernel globally and wraps the request processing logic within a `run()` function, utilizing output buffering (`ob_start`, `ob_get_clean`) to capture the response body. ```php global $kernel; $kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']); function run() { global $kernel; ob_start(); $request = Request::createFromGlobals(); $response = $kernel->handle($request); $response->send(); $kernel->terminate($request, $response); return ob_get_clean(); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.