Skip to content

Commit 7bf7189

Browse files
committed
feat: add function num_available_processors
Signed-off-by: Daniel Kesselberg <[email protected]>
1 parent 5187ff2 commit 7bf7189

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

ext/standard/basic_functions.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2578,3 +2578,23 @@ PHP_FUNCTION(sys_getloadavg)
25782578
}
25792579
/* }}} */
25802580
#endif
2581+
2582+
PHP_FUNCTION(num_available_processors)
2583+
{
2584+
ZEND_PARSE_PARAMETERS_NONE();
2585+
2586+
#if defined(_SC_NPROCESSORS_ONLN)
2587+
int nprocs = sysconf(_SC_NPROCESSORS_ONLN);
2588+
if (nprocs > 0) {
2589+
RETURN_LONG(nprocs);
2590+
}
2591+
#elif defined _WIN32 && ! defined __CYGWIN__
2592+
SYSTEM_INFO system_info;
2593+
GetSystemInfo (&system_info);
2594+
if (system_info.dwNumberOfProcessors > 0) {
2595+
RETURN_LONG(system_info.dwNumberOfProcessors);
2596+
}
2597+
#endif
2598+
2599+
RETURN_NULL();
2600+
}

ext/standard/basic_functions.stub.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3834,3 +3834,5 @@ function sapi_windows_set_ctrl_handler(?callable $handler, bool $add = true): bo
38343834

38353835
function sapi_windows_generate_ctrl_event(int $event, int $pid = 0): bool {}
38363836
#endif
3837+
3838+
function num_available_processors(): ?int {}

ext/standard/basic_functions_arginfo.h

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
num_available_processors() tests
3+
--SKIPIF--
4+
<?php
5+
if (!function_exists("num_available_processors")) die("skip");
6+
?>
7+
--FILE--
8+
<?php
9+
10+
var_dump(num_available_processors());
11+
12+
echo "Done\n";
13+
?>
14+
--EXPECTF--
15+
int(%d)
16+
Done

0 commit comments

Comments
 (0)