Table of Contents

PHP RFC: num_available_processors

Introduction

The number of available processors is valuable for tools like php-cs-fixer, enabling parallel execution, or when used with semaphores to manage the concurrent execution of resource-intensive tasks. The new num_available_processors function simplifies getting the number of logical processors across various operating systems.

Proposal

This RFC proposes the addition of a new function that retrieves the number of available processors:

function num_available_processors(): ?int

Backward Incompatible Changes

None.

Proposed PHP Version(s)

Next PHP 8.x

RFC Impact

This RFC introduces a new function, which might affect existing userland extensions if developers have already created helper functions with the same name. Since the proposed function has a clear and meaningful name, any custom functions should ideally do the same thing and be easy to replace.

There is no impact on SAPIs or the opcache.

Future Scope

There has already been some discussion on the GitHub pull request. While not currently proposed, a valuable addition could be the introduction of a class such as ReflectionServer or, OS (similar to Node.js, https://nodejs.org/api/os.html) to provide information about the underlying system. Existing functions like sys_getloadavg or php_uname could be integrated into this class.

Proposed Voting Choices

Include these so readers know where you are heading and can discuss the proposed voting options.

Patches and Tests

https://github.com/php/php-src/pull/11137 (the current prototype, probably just a rename of the function is necessary)

Implementation

After the project is implemented, this section should contain

  1. the version(s) it was merged into
  2. a link to the git commit(s)
  3. a link to the PHP manual entry for the feature
  4. a link to the language specification section (if any)

References

Links to external references, discussions or RFCs

Rejected Features

Keep this updated with features that were discussed on the mail lists.