Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127449 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by lists.php.net (Postfix) with ESMTPS id 4318C1A00BC for ; Sat, 24 May 2025 20:43:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1748119276; bh=Qgy5wRkkv4e8+7oBbyIqrwB+caAFyNzQouxSswYcCr4=; h=Date:From:To:In-Reply-To:References:Subject:From; b=FX9YddDDE0un/tswjtVXvwZVRF6hZr6sDW9prD98kfWNvPCwTMliFN8Ff7k5Z2vy4 XALjTUK5ZPOpfaSwlXH5jQSAgGB29z4qLCxV8WPWXDV6NPHkM2ZZUl/HPwgbilGftO xRGDHhuDIR4k9VHD6d2oKIWxZucqAUcvseGMy3Am0v/KZ4uYb+aBaPntHbWY/x9Bgb rneTPktI0ETY3nyOZzJwfDy62+MAO/R7iQQ9DOYDh3kn+rTb2XzF8MbyvAf5l/ie5O fBz/Vy53g6OrqR90z8F7eMUQzJ4os0EBFGCEuKcHmuijK6VMoSGXAR1LbzYZrG2mr4 uyubXru2c7XBw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7AA271801DF for ; Sat, 24 May 2025 20:41:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-3.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS, SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from fout-b5-smtp.messagingengine.com (fout-b5-smtp.messagingengine.com [202.12.124.148]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 24 May 2025 20:41:15 +0000 (UTC) Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfout.stl.internal (Postfix) with ESMTP id 867491140084 for ; Sat, 24 May 2025 16:43:22 -0400 (EDT) Received: from phl-imap-09 ([10.202.2.99]) by phl-compute-05.internal (MEProxy); Sat, 24 May 2025 16:43:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; h=cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1748119402; x=1748205802; bh=Qgy5wRkkv4 e8+7oBbyIqrwB+caAFyNzQouxSswYcCr4=; b=Gp7v8s6uGSD6oqyo4K6UJhxB3T 3kgi3OMT8EIjoLlZ1Xffuab+6AbE1XciBg82lGctFcYScxW+J4Y7NqdfQjhHsrGZ R/yR4fphcOx+2Aj5dItOe44jj2zcEdVFKoAKXtx0qbOf3q78Pk6B+P49/Hwctcth B+W/HlyhzxIHJqcYqJ3xllPH8emJmvuiwsFPyHCq7GM3qcaRSHbqoYY4UbnGBc/F r52n/HGpi6V/cogOWTLmoBYdvBlSeiRGx1ABBgmyoRxWgABsK0A8bg87bNyG9YAD 4oa+Tj+nspS30nuwV9e3t0XZhfTKIJee7umx23W1Wr9zbgaEPm85eEnDo2TQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1748119402; x=1748205802; bh=Qgy5wRkkv4e8+7oBbyIqrwB+caAFyNzQoux SswYcCr4=; b=XEAWkVy7L+lJl0foDhf6ZNKPTAFpOMOMZeoK9ry8aZZzcFpjgVF FvcKH0e4FjnvushR85kc2R3uP+wT3p/TxMMuEnegE4a9q9Qz8VR6Lywoh6eVA6K2 EpdvFi+GTFwQ7Fpa0xPsmG49a1tL+c7rmdDeY2uBbuvm9AlMY3uV+AONFbJTp7CB bQ4U/CPnc1zrBvK7o5J2wGeoASlWCniAEL/dNBsJ0zuZugh08WXpMm1qhT2XWs4m RKKPXzIezSFHYBxKePJI1/jxOevwWH5dPN7Np7XdUQeG7syVwOKfzTqd/Jg1aESu qVS2KqSvNobtlRI1AyhhuRbvDxyB/0KswLw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtddtgdduvdeileculddtuddrgeefvddrtd dtmdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggft fghnshhusghstghrihgsvgdpuffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftd dtnecunecujfgurhepofggfffhvffkjghfufgtsegrtderreertdejnecuhfhrohhmpedf tfhosgcunfgrnhguvghrshdfuceorhhosgessghothhtlhgvugdrtghouggvsheqnecugg ftrfgrthhtvghrnhepiedthffhvdffhfettdfgveefgfeugeegudeukeejheeigefghfei veelfeefueefnecuffhomhgrihhnpehgihhthhhusgdrtghomhenucevlhhushhtvghruf hiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehrohgssegsohhtthhlvggurdgt ohguvghspdhnsggprhgtphhtthhopedupdhmohguvgepshhmthhpohhuthdprhgtphhtth hopehinhhtvghrnhgrlhhssehlihhsthhsrdhphhhprdhnvght X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id E722F3020061; Sat, 24 May 2025 16:43:21 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 X-ThreadId: Ta0643016bd41e344 Date: Sat, 24 May 2025 22:43:01 +0200 To: internals@lists.php.net Message-ID: <36cd6421-482e-4699-858b-660e2128c0f1@app.fastmail.com> In-Reply-To: <57f7ed3e-6bef-434d-83db-fd729ff43fc9@gmail.com> References: <8b76a3d4-4583-4849-a75f-00f645191247@gmail.com> <57f7ed3e-6bef-434d-83db-fd729ff43fc9@gmail.com> Subject: Re: [PHP-DEV] [RFC] Add num_available_processors Content-Type: multipart/alternative; boundary=a8d4207f4a50441282a28ba0ea9d4e3e From: rob@bottled.codes ("Rob Landers") --a8d4207f4a50441282a28ba0ea9d4e3e Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Sat, May 24, 2025, at 22:28, Niels Dossche wrote: > On 24/05/2025 21:24, Rob Landers wrote: > >=20 > >=20 > > 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 chec= ked at configure time and the function should be made conditionally avai= lable. > >> That way, the return type can just be "int". > >> > >> Kind regards > >> Niels > >> > >=20 > > I=E2=80=99m curious why you say this is an =E2=80=9Canti pattern=E2=80= =9D? I do agree that it should return a number or throw. >=20 > If you make the function unconditionally available, yet specifying the= return type as ?int, then you give the false impression that it _can_ w= ork even if your platform doesn't support it. >=20 > Also: IMO new APIs should fail hard with an exception if they can't do= their main task, that's our error "channel". >=20 > > There are various error conditions it should throw (at least on Linu= x) so having it throw an exception when there isn=E2=80=99t a way to cou= nt any processors makes more sense than returning null. >=20 > Throwing is indeed preferable. > What are the error conditions on Linux? >=20 > >=20 > > It could also be someone patching libc to get around per-core licens= ing too. I=E2=80=99ve seen the latter more often than the former.=20 > I don't follow. > In any case, if you run a monkey patched libc and you're breaking the = consumer expectations of said libc, then you deserve getting it blown up= in your face imo. >=20 > Kind regards > Niels >=20 I think we both agree it should blow up. Error conditions (for Linux) using the current method in the patch are e= ither -1 or 0. -1 is just a possible return for that function which coul= d indicate that the kernel doesn=E2=80=99t have support for that sysconf= value or there are infinite cores =E2=80=94 you=E2=80=99d have to check= errno.=20 It might also report 0, which technically isn=E2=80=99t an error (hotplu= gging cpus for instance). It could also just be a bug. This is a fun one= : https://github.com/lxc/lxcfs/issues/469 Also, I wouldn=E2=80=99t be surprised to see a container with very small= amounts of cpu allocated getting rounded to zero. But in any case, zero= should probably be treated as an error IMHO. =E2=80=94 Rob --a8d4207f4a50441282a28ba0ea9d4e3e Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable


On Sat, May 24, 2025, at 22:28, Niels Dossche wrote:
On 24/05/2025 21= :24, Rob Landers wrote:
<= div>> On Sat, May 24, 2025, at 19:42, Niels Dossche wrote:
= >> Hi
>>
>> In my opinion, the ret= urn type should not be nullable.
>> Returning NULL when = the platform (or PHP on that platform) doesn't support getting this info= rmation 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".
>>
&g= t;> Kind regards
>> Niels
>>
> I=E2=80=99m curious why you say this is an =E2= =80=9Canti pattern=E2=80=9D? I do agree that it should return a number o= r throw.

If you make the function unconditional= ly available, yet specifying the return type as ?int, then you give the = false impression that it _can_ work even if your platform doesn't suppor= t it.

Also: IMO new APIs should fail hard with = an exception if they can't do their main task, that's our error "channel= ".

> There are various error conditions it s= hould throw (at least on Linux) so having it throw an exception when the= re isn=E2=80=99t a way to count any processors makes more sense than ret= urning null.

Throwing is indeed preferable.
What are the error conditions on Linux?

= > 
> It could also be someone patching libc to get = around per-core licensing too. I=E2=80=99ve seen the latter more often t= han the former. 
I don't follow.
In any case, i= f you run a monkey patched libc and you're breaking the consumer expecta= tions of said libc, then you deserve getting it blown up in your face im= o.

Kind regards
Niels

<= /div>

I think we both agree it should bl= ow up.

Error conditions (for Linux) using the c= urrent method in the patch are either -1 or 0. -1 is just a possible ret= urn for that function which could indicate that the kernel doesn=E2=80=99= t have support for that sysconf value or there are infinite cores =E2=80= =94 you=E2=80=99d have to check errno. 

It= might also report 0, which technically isn=E2=80=99t an error (hotplugg= ing cpus for instance). It could also just be a bug. This is a fun one:&= nbsp;https://github.= com/lxc/lxcfs/issues/469

Also, I wouldn=E2=80= =99t be surprised to see a container with very small amounts of cpu allo= cated getting rounded to zero. But in any case, zero should probably be = treated as an error IMHO.

=E2= =80=94 Rob
--a8d4207f4a50441282a28ba0ea9d4e3e--