PHP code example of statix / server

1. Go to this page and download the library: Download statix/server 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/ */

    

statix / server example snippets


use Statix\Server\Server;

// or 

(new Server)->start();

use Statix\Server\Server;

Server::new([
    'host' => 'localhost',
    'port' => 8000,
    'root' => __DIR__ . '/content'
]);

// or 

new Server([
    'host' => 'localhost',
    'port' => 8000,
    'root' => __DIR__ . '/content'
]);

$optionsSettableViaContructor = [
    'host' => 'string', // default: localhost
    'port' => 'string|int', // default: 8000
    'root' => 'string', // default: getcwd()
    'router' => 'string', // path to your routing script
    'php' => 'string', // path to the desired PHP binary to use for the server process
    'withEnvVars' => [
        'APP_DYNAMIC_ENV' => 'server'
    ],
    'withoutEnvVars' => [ 
        'APP_KEY'
    ]
];

use Statix\Server\Server;

Server::new()
    ->php('path') 
    ->host('localhost') 
    ->port('8080') 
    ->root('./content')
    ->router('./router.php')
    ->withEnvVars([
        'APP_DYNAMIC_ENV' => 'server'
    ])->withoutEnvVars([
        'APP_KEY',
    ])->withEnvFile('path/to/.env');

Server::new()
    ->output(function($output) {
        echo $output;
    })->start();

Server::new()->runInBackground();

$server = Server::new()->withEnvVars([
    'APP_NAME' => 'statix/server',
]);

$server->isRunning(); // false

$server->runInBackground();

$server->isRunning(); // true

$server = Server::new()->runInBackground();

// do work

$server->stop();

$server = Server::new()->runInBackground();

// do work

$server->restart();

// do more work

$server->stop();

git clone https://github.com/statix-php/server.git