承接 wyrihaximus/cpu-core-detector 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

wyrihaximus/cpu-core-detector

最新稳定版本:2.0.0

Composer 安装命令:

composer require wyrihaximus/cpu-core-detector

包简介

Detect how many CPU cores are available

README 文档

README

This PHP script detects the number of CPU cores available on a Linux server. It can be helpful for optimizing performance in multi-threaded applications by dynamically assessing hardware capabilities.

Purpose

This tool enables developers to retrieve the number of CPU cores on a Linux server using PHP. This is especially useful for performance optimizations and load balancing in server environments.

Features

  • Detects the number of CPU cores on Linux-based systems.
  • Utilizes shell commands (hash, nproc, taskset) to gather system information.
  • Lightweight and easy to integrate into existing PHP applications.

Supported OS/Programs

Currently supports Linux only, using the following utilities:

  • hash
  • nproc
  • taskset

Clone this repository:

git clone https://github.com/your-user/php-cpu-core-detection.git

Contributing

Contributions are welcome! To contribute:

  1. Fork this repository.
  2. Make your changes in a new branch.
  3. Submit a pull request with a detailed description of your changes.

Examples

Check out these examples to see the CPU core detection in action:

Async

$loop = Factory::create();

Detector::detectAsync($loop)->then(function ($result): void {
   echo $result, \PHP_EOL;
   for ($i = 0; $i < $result; $i++) {
       Resolver::resolve($i, 'uptime')->then(function ($cmd): void {
           echo $cmd, \PHP_EOL;
       });
   }
});

$loop->run();

Full Example

Sync

$result = Detector::detect();
echo $result, \PHP_EOL;

for ($i = 0; $i < $result; $i++) {
   Resolver::resolve((string)$i, 'uptime')->then(function ($cmd): void {
       echo $cmd, \PHP_EOL;
   });
}

Full Example

License

Copyright 2016 Cees-Jan Kiewiet

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

统计信息

  • 总下载量: 263.32k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 8
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 8
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-01-29