{"id":21000397,"url":"https://github.com/statix-php/server","last_synced_at":"2025-05-14T23:31:36.034Z","repository":{"id":49362023,"uuid":"514958295","full_name":"statix-php/server","owner":"statix-php","description":"An object oriented wrapper around PHP's built-in server.","archived":false,"fork":false,"pushed_at":"2023-03-05T19:37:35.000Z","size":224,"stargazers_count":117,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-03T00:51:56.694Z","etag":null,"topics":["php","server","statix","statix-php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/statix-php.png","metadata":{"files":{"readme":"readme.md","changelog":"changelog.md","contributing":null,"funding":null,"license":"license.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-07-17T21:21:56.000Z","updated_at":"2023-06-23T14:28:22.000Z","dependencies_parsed_at":"2022-08-12T20:10:53.416Z","dependency_job_id":null,"html_url":"https://github.com/statix-php/server","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statix-php%2Fserver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statix-php%2Fserver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statix-php%2Fserver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statix-php%2Fserver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/statix-php","download_url":"https://codeload.github.com/statix-php/server/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254248291,"owners_count":22039002,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["php","server","statix","statix-php"],"created_at":"2024-11-19T08:10:16.585Z","updated_at":"2025-05-14T23:31:31.012Z","avatar_url":"https://github.com/statix-php.png","language":"PHP","readme":"# Statix Server\n\nStatix Server is a PHP package that provides a simple way to configure and start a local PHP server for your web development needs.\n\n![Banner image](.art/banner.jpg)\n\n## Requirements\n\n- PHP 8 minumum\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require statix/server\n```\n\nView on packagist: [https://packagist.org/packages/statix/server](https://packagist.org/packages/statix/server)\n\n## Basic Usage\n\nTo get started, require the vendor autoload script and create an instance of the `Server` class. After setting any [configuration options](#configuration), call the `start` method to start the server.\n\n```php\nuse Statix\\Server\\Server;\n\nrequire_once './vendor/autoload.php';\n\nServer::new()-\u003estart();\n\n// or \n\n(new Server)-\u003estart();\n```\n\n## Configuration\n\nYou can configure the several options with the server, such as the host, the port, the root directory and more. Please read more below for a detailed explanation of each configuration method.\n\n### Passing configuration via the constructor or Server::new()\n\nYou may pass most configuration options via the constructor. For example we are setting the `host`, `port` and `root` options in the code below. \n\n```PHP\nuse Statix\\Server\\Server;\n\nServer::new([\n    'host' =\u003e 'localhost',\n    'port' =\u003e 8000,\n    'root' =\u003e __DIR__ . '/content'\n]);\n\n// or \n\nnew Server([\n    'host' =\u003e 'localhost',\n    'port' =\u003e 8000,\n    'root' =\u003e __DIR__ . '/content'\n]);\n```\n\nThe complete list of configuration items that can be passed via the constructor can be found below. \n\n```PHP\n$optionsSettableViaContructor = [\n    'host' =\u003e 'string', // default: localhost\n    'port' =\u003e 'string|int', // default: 8000\n    'root' =\u003e 'string', // default: getcwd()\n    'router' =\u003e 'string', // path to your routing script\n    'php' =\u003e 'string', // path to the desired PHP binary to use for the server process\n    'withEnvVars' =\u003e [\n        'APP_DYNAMIC_ENV' =\u003e 'server'\n    ],\n    'withoutEnvVars' =\u003e [ \n        'APP_KEY'\n    ]\n];\n```\n\n### Setting configuration via named methods\n\nYou also have the option of calling named methods to set the configuration options as shown below. \n\n```PHP\nuse Statix\\Server\\Server;\n\nServer::new()\n    -\u003ephp('path') \n    -\u003ehost('localhost') \n    -\u003eport('8080') \n    -\u003eroot('./content')\n    -\u003erouter('./router.php')\n    -\u003ewithEnvVars([\n        'APP_DYNAMIC_ENV' =\u003e 'server'\n    ])-\u003ewithoutEnvVars([\n        'APP_KEY',\n    ])-\u003ewithEnvFile('path/to/.env');\n```\n\n### Capturing the output from the server process\n\nIf you want to show the output from the server process as it recieves and handles requests, you may call the `output` method and pass a callback function that will be called and passed any output of the process.\n\n```PHP\nServer::new()\n    -\u003eoutput(function($output) {\n        echo $output;\n    })-\u003estart();\n```\n\n### Running the process in the background\n\nYou may find it useful to run the server process in the background, you may call `runInBackground()`. The process will run as long as the parent script is running. \n\n```PHP\nServer::new()-\u003erunInBackground();\n```\n\n### Checking whether the process is running\n\nYou may check whether or not the server is currently running by calling the `isRunning` method.\n\n```PHP\n$server = Server::new()-\u003ewithEnvVars([\n    'APP_NAME' =\u003e 'statix/server',\n]);\n\n$server-\u003eisRunning(); // false\n\n$server-\u003erunInBackground();\n\n$server-\u003eisRunning(); // true\n```\n\n### Stopping the server\n\nYou may stop the process running the sever by calling the stop command on an instance of the server class. If the server is not currently running this method will return `null` otherwise it will return an array container first the process exit code and second the process exit text. Note this command can only be called when the server is running in the background.\n\n```PHP\n$server = Server::new()-\u003erunInBackground();\n\n// do work\n\n$server-\u003estop();\n```\n\n### Restarting the server\n\nYou can restart the server by calling the `restart` method on an instance of the server class. An example of why you might need to restart the server is detecting when your `.env` file is changed, you could restart the server and ensure the env vars are loaded.\n\n```PHP\n$server = Server::new()-\u003erunInBackground();\n\n// do work\n\n$server-\u003erestart();\n\n// do more work\n\n$server-\u003estop();\n```\n\n## Contributing\n\n#### Installation\n\n1. Clone repo \n\n```\ngit clone https://github.com/statix-php/server.git\n```\n\n2. Install php dependencies\n\n```\ncomposer install\n```\n\n#### Testing\n\nWe use [Pest PHP](https://pestphp.com/) for the test suite, please ensure before pushing changes you confirm there are no breaking changes by running the command below. Additionally, tests for new features are highly encouraged, changes will be considered without tests but it will increase the time to accept / merge. \n\n```bin\n./vendor/bin/pest\n```\n\n#### Style\n\nWe use [Laravel Pint](https://github.com/laravel/pint) to automatically standardize code styling, before pushing changes please run `pint` using the command below. \n\n```bin\n./vendor/bin/pint\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstatix-php%2Fserver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstatix-php%2Fserver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstatix-php%2Fserver/lists"}