1. Go to this page and download the library: Download dvaknheo/workermanhttpd library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
$options = [
// listen
'host' => '127.0.0.1',
'port' => 8080,
// Workerman
'worker_name' => 'WorkermanHttpd',
'worker_count' => -1, // -1 = CPU cores x 2
'worker_properties' => [], // assigned straight onto Workerman\Worker
'pid_file' => null, // becomes Worker::$pidFile; used by getPid()/close()
'stdout_file' => null, // becomes Worker::$stdoutFile
'command' => 'start', // start / stop / reload / restart
'background' => false, // daemon mode (not supported on Windows)
'gracefull' => false, // -g graceful restart
// request / paths
'path' => '', // project root; defaults to the startup cwd
'doc_root' => null, // $_SERVER['DOCUMENT_ROOT']; auto-detects path/public
'request_class' => '', // defaults to WorkermanHttpd\Request
'http_enable_cache' => false, // Workerman's request-object cache; must stay off in a worker
// DuckPhp
'http_app_class' => null, // FQCN of the DuckPhp application class
'http_app_options' => [], // extra options merged into the application
// Components renewed for each request (clone + re-init). See below.
// Set to false to disable the per-request container entirely.
'http_app_renew_classes' => [
'DuckPhp\\Core\\Route', 'DuckPhp\\Core\\View', 'DuckPhp\\Component\\Lang',
],
// http_handler mode
'http_handler' => null,
'http_exception_handler' => null,
'http_404_handler' => null,
// file modes
'http_handler_basepath' => '', // prefix for the two paths below
'http_handler_root' => null, // document root: resolve a file per URL path
'http_handler_file' => null, // single entry file: every URL goes here
'with_http_handler_root' => false, // let a false http_handler fall through
'with_http_handler_file' => false, // let a root miss fall through to the entry file
'enable_resource_file' => true, // send non-PHP files found under the root
];
// Equivalent to nginx's `root`: run the PHP file a URL resolves to, send static files.
\WorkermanHttpd\WorkermanHttpd::RunQuickly([
'port' => 8080,
'http_handler_root' => __DIR__.'/public',
]);
// Single entry file: every URL is handled by one file (REQUEST_URI/PATH_INFO preserved).
\WorkermanHttpd\WorkermanHttpd::RunQuickly([
'port' => 8080,
'http_handler_file' => __DIR__.'/public/index.php',
]);
shell
php bin/cli.php run --http_server=WorkermanHttpd/HttpServerForDuckPhp --port=8080