<commit_before><?php
declare(strict_types=1);

namespace ManaPHP\Http\Server\Adapter;

use ManaPHP\Helper\Ip;
use ManaPHP\Http\AbstractServer;

/**
 * @property-read \ManaPHP\Http\Server\Adapter\Native\SenderInterface     $sender
 * @property-read \ManaPHP\Http\RouterInterface                           $router
 * @property-read \ManaPHP\Http\Server\Adapter\Php\StaticHandlerInterface $staticHandler
 * @property-read \ManaPHP\AliasInterface                                 $alias
 */
class Php extends AbstractServer
{
    public function __construct(string $host = '0.0.0.0', int $port = 9501)
    {
        parent::__construct($host, $port);

        $argv = $GLOBALS['argv'] ?? [];
        foreach ($argv as $k => $v) {
            if ($v === '--port' || $v === '-p') {
                if (isset($argv[$k + 1])) {
                    $this->port = ($argv[$k + 1]);
                    break;
                }
            }
        }

        $public_dir = $this->alias->resolve('@public');
        $local_ip = $this->host === '0.0.0.0' ? Ip::local() : $this->host;

        $_SERVER['REQUEST_SCHEME'] = 'http';

        if (PHP_SAPI === 'cli') {
            $e = extension_loaded('yasd') && ini_get('opcache.optimization_level') === '0' ? '-e' : '';
            $index = @get_included_files()[0];
            $cmd = "php $e -S $this->host:$this->port -t $public_dir  $index";
            console_log('info', $cmd);
            $prefix = $this->router->getPrefix();
            console_log('info', "http://127.0.0.1:$this->port" . ($prefix ?: '/'));
            shell_exec($cmd);
            exit(0);
        } else {
            $_SERVER['SERVER_ADDR'] = $local_ip;
            $_SERVER['SERVER_PORT'] = $this->port;
        }
    }

    protected function prepareGlobals(): void
    {
        $rawBody = file_get_contents('php://input');
        $this->globals->prepare($_GET, $_POST, $_SERVER, $rawBody, $_COOKIE, $_FILES);
    }

    public function start(): void
    {
        $this->prepareGlobals();

        if ($this->staticHandler->isStaticFile()) {<commit_msg>add multiple process supporting for ManaPHP\Http\Server\Adapter\Php<commit_after><?php
declare(strict_types=1);

namespace ManaPHP\Http\Server\Adapter;

use ManaPHP\Helper\Ip;
use ManaPHP\Http\AbstractServer;

/**
 * @property-read \ManaPHP\Http\Server\Adapter\Native\SenderInterface     $sender
 * @property-read \ManaPHP\Http\RouterInterface                           $router
 * @property-read \ManaPHP\Http\Server\Adapter\Php\StaticHandlerInterface $staticHandler
 * @property-read \ManaPHP\AliasInterface                                 $alias
 */
class Php extends AbstractServer
{
    public function __construct(string $host = '0.0.0.0', int $port = 9501, array $settings = [])
    {
        parent::__construct($host, $port);

        $argv = $GLOBALS['argv'] ?? [];
        foreach ($argv as $k => $v) {
            if ($v === '--port' || $v === '-p') {
                if (isset($argv[$k + 1])) {
                    $this->port = ($argv[$k + 1]);
                    break;
                }
            }
        }

        $public_dir = $this->alias->resolve('@public');
        $local_ip = $this->host === '0.0.0.0' ? Ip::local() : $this->host;

        $_SERVER['REQUEST_SCHEME'] = 'http';

        if (PHP_SAPI === 'cli') {
            if (($worker_num = $settings['worker_num'] ?? 1) > 1) {
                putenv("PHP_CLI_SERVER_WORKERS=$worker_num");
            }

            $e = extension_loaded('yasd') && ini_get('opcache.optimization_level') === '0' ? '-e' : '';
            $index = @get_included_files()[0];
            $cmd = "php $e -S $this->host:$this->port -t $public_dir  $index";
            console_log('info', $cmd);
            $prefix = $this->router->getPrefix();
            console_log('info', "http://127.0.0.1:$this->port" . ($prefix ?: '/'));
            shell_exec($cmd);
            exit(0);
        } else {
            $_SERVER['SERVER_ADDR'] = $local_ip;
            $_SERVER['SERVER_PORT'] = $this->port;
        }
    }

    protected function prepareGlobals(): void
    {
        $rawBody = file_get_contents('php://input');
        $this->globals->prepare($_GET, $_POST, $_SERVER, $rawBody, $_COOKIE, $_FILES);
    }

    public function start(): void
    {
        $this->prepareGlobals();

        if ($this->staticHandler->isStaticFile()) {
{'fraction_non_alphanumeric': 0.1792819574662703, 'fraction_numerical': 0.01143379830779785, 'mean_word_length': 2.0889830508474576, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 38, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 6, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5495291', 'n_tokens_mistral': 1402, 'n_tokens_neox': 1351, 'n_words': 239}