Re: [RFC] Add num_available_processors

From: Date: Sat, 24 May 2025 19:24:24 +0000
Subject: Re: [RFC] Add num_available_processors
References: 1 2  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message


On Sat, May 24, 2025, at 19:42, Niels Dossche wrote:
> Hi
> 
> In my opinion, the return type should not be nullable.
> Returning NULL when the platform (or PHP on that platform) doesn't support getting this
> information is an anti-pattern.
> Instead, availability of the necessary functionality should be checked at configure time and
> the function should be made conditionally available.
> That way, the return type can just be "int".
> 
> Kind regards
> Niels
> 

I’m curious why you say this is an “anti pattern”? I do agree that it should return a number
or throw. There are various error conditions it should throw (at least on Linux) so having it throw
an exception when there isn’t a way to count any processors makes more sense than returning null.

I also note the patch is using the sysconf method and not checking the error on a negative one
result and not properly handling zero. Naturally, this means something might be catastrophically
wrong, but it should still throw instead of returning null. It could also be someone patching libc
to get around per-core licensing too. I’ve seen the latter more often than the former. 

— Rob


Thread (21 messages)

« previous php.internals (#127447) next »