Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127447 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 C522E1A00BC for ; Sat, 24 May 2025 19:24:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1748114568; bh=7ebckApBoerHCx7DV6Uiia2DcVsZIIe5jp3tTm6Bqt4=; h=Date:From:To:In-Reply-To:References:Subject:From; b=dYpxf7bTwVdtQuZJAuFZdXaSAckP9QiY5wp6Pt9/pHpFABuvuG7ubtSXI/gENfdTL vCFj6I/a4McxFl5Ioc7haoz66rArCEK76UrehAdEvJsB/Iiy82HD3FixQexAGbzC8q xD/W8BpovFqTqcVUiOPCcyvDuF3X+Ps6sPdDHUP8EA5nWNUMUy4eo3an3KnrRTPzov mdTQ12YiXYmKoJvv7uUdGrfG9cLWxfMEgHS/2ZbSrzVen0rz4T6M91pCdrkcIH8RuW Nac0F1stUz/FjUxjN+xo/jbFT4AMC0OkJRRoJm69iS6+9nd89KPkHXvTir0q3y6YdS HKXBHluOXbsMQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 50794180068 for ; Sat, 24 May 2025 19:22:48 +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=-2.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,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 fhigh-b3-smtp.messagingengine.com (fhigh-b3-smtp.messagingengine.com [202.12.124.154]) (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 19:22:38 +0000 (UTC) Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfhigh.stl.internal (Postfix) with ESMTP id 5AE4425400EE for ; Sat, 24 May 2025 15:24:45 -0400 (EDT) Received: from phl-imap-09 ([10.202.2.99]) by phl-compute-05.internal (MEProxy); Sat, 24 May 2025 15:24:45 -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=1748114685; x=1748201085; bh=7ebckApBoe rHCx7DV6Uiia2DcVsZIIe5jp3tTm6Bqt4=; b=WF6b7bi0ZciqpBLcTcQmRfdZcc 0PcjR+k4vY9ZN5HwSLpZqJ/0t/ICRJZGFTUF6hsURbBiQfFGWwpC2OOuXbZztS4y W0ByiPxz4mEmrF3Wz4WxS+suMt+ZD8iHlfz7lYYdpMXrObzngEKo1FXJ631pGoNJ vf6fkjDV/1n/lAhfYdNRQuqGDd3FdvE0AWSP0R1BZRJrNAcK6jBLIcqaBM2qZwEM jul80hxbVkF5rdLSR9qsxSkZLiZcndQN35qwJiulawUfUv0+0jkGgb0v+sRSDvdR 4Dobjw75KQWx7D4PBFvAyOHsbC8kUfZu3+GG/grR9fVgKEKC/BIaGEnuvazA== 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= 1748114685; x=1748201085; bh=7ebckApBoerHCx7DV6Uiia2DcVsZIIe5jp3 tTm6Bqt4=; b=iz0kNGTPeHe29omQbJWgQqY/J2alvu/lF9WzOq96XL/XNZHpwyl 5VjyKUKNK4Ifh3A4zBRroFxBhXNCcbwDsE580xuvLD7BDAzpRwhO8CvUzX9KNDo7 HKVsQbM6i87l4gK+/fHMtrrkY+FHeJJrmweptk5qfQmtersKM7Mp+5WKkRhYfEpj XY7IanjvYBl+nKulgnv233JRSaWHUKlnslfu717rvnVkGf+clV6p4327vmTV0aEM y/VDRdQsXJGJ3sSFg8GdkfAIb/szqgnG2xkt+8Z7ClCiWlwrIzuzxaY6nrgxBm7I pm9YbcHM5t+rkr3TgbQarfF0TqerS5GfVGQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtddtgdduvdehieculddtuddrgeefvddrtd dtmdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggft fghnshhusghstghrihgsvgdpuffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftd dtnecunecujfgurhepofggfffhvffkjghfufgtsegrtderreertdejnecuhfhrohhmpedf tfhosgcunfgrnhguvghrshdfuceorhhosgessghothhtlhgvugdrtghouggvsheqnecugg ftrfgrthhtvghrnheptdeujedttefhueelhfdtleeiudetlefftdduleehffegtdeihefh leeijefgveegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrh homheprhhosgessghothhtlhgvugdrtghouggvshdpnhgspghrtghpthhtohepuddpmhho uggvpehsmhhtphhouhhtpdhrtghpthhtohepihhnthgvrhhnrghlsheslhhishhtshdrph hhphdrnhgvth X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id D7AFF3020061; Sat, 24 May 2025 15:24:44 -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 21:24:24 +0200 To: internals@lists.php.net Message-ID: In-Reply-To: <8b76a3d4-4583-4849-a75f-00f645191247@gmail.com> References: <8b76a3d4-4583-4849-a75f-00f645191247@gmail.com> Subject: Re: [PHP-DEV] [RFC] Add num_available_processors Content-Type: multipart/alternative; boundary=b91e5aded8664fdf801c08c8a7eb1f61 From: rob@bottled.codes ("Rob Landers") --b91e5aded8664fdf801c08c8a7eb1f61 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Sat, May 24, 2025, at 19:42, Niels Dossche wrote: > Hi >=20 > In my opinion, the return type should not be nullable. > Returning NULL when the platform (or PHP on that platform) doesn't sup= port 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 availab= le. > That way, the return type can just be "int". >=20 > 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. There are various = error conditions it should throw (at least on Linux) so having it throw = an exception when there isn=E2=80=99t a way to count any processors make= s more sense than returning null. I also note the patch is using the sysconf method and not checking the e= rror on a negative one result and not properly handling zero. Naturally,= this means something might be catastrophically wrong, but it should sti= ll throw instead of returning null. It could also be someone patching li= bc to get around per-core licensing too. I=E2=80=99ve seen the latter mo= re often than the former.=20 =E2=80=94 Rob --b91e5aded8664fdf801c08c8a7eb1f61 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable


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 configu= re time and the function should be made conditionally available.
That way, the return type can just be "int".

Kind regards
Niels


=
I=E2=80=99m curious why you say this is an =E2=80=9Canti patt= ern=E2=80=9D? I do agree that it should return a number or throw. There = are various error conditions it should throw (at least on Linux) so havi= ng it throw an exception when there isn=E2=80=99t a way to count any pro= cessors makes more sense than returning null.

I= also note the patch is using the sysconf method and not checking the er= ror on a negative one result and not properly handling zero. Naturally, = this means something might be catastrophically wrong, but it should stil= l throw instead of returning null. It could also be someone patching lib= c to get around per-core licensing too. I=E2=80=99ve seen the latter mor= e often than the former. 

=E2=80=94 Rob
--b91e5aded8664fdf801c08c8a7eb1f61--