Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126165 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 qa.php.net (Postfix) with ESMTPS id 4EB471A00BD for ; Sun, 22 Dec 2024 12:16:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1734869632; bh=L0CMW7cNk06jC6Hndh2+yTSLN8oiPrd/FRup+3dC3Us=; h=Date:Subject:To:References:From:In-Reply-To:From; b=FEn0s7TyevgnxpJuYFOAEwxkYT0QG2dBsABuUqHLkH7zXdY/gcHhuK9OeD+CJhG03 DynoCMBZ+zCrqf41kyT/dh58Yfv89oshn37XfNkZd38Ua4XKkn5sce2nwhgD1iaXyU U8QQAQ9+G0A9Ts/YwPSqo6iA3e1Lp0uzAI6g/Yj1TlfiyvhnpX5r1ZxbPUK3F+hfcV QSV8FXffnP6Zj1/RHSzOtENojI02SEahg1D7hyumRyWt8vwRDYSUzUVrqIK7k8FUaE 3ohi0qLDaTFmbwCK/CipErGloh/mvAHbCk7aBg5kGyehYOVwVlWpJVegsntA2BFYz4 BCxAi/Z0n51Fg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1AFCB18003E for ; Sun, 22 Dec 2024 12:13:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=BAYES_50,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.0 X-Spam-Virus: No X-Envelope-From: Received: from fout-a8-smtp.messagingengine.com (fout-a8-smtp.messagingengine.com [103.168.172.151]) (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 ; Sun, 22 Dec 2024 12:13:50 +0000 (UTC) Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfout.phl.internal (Postfix) with ESMTP id C6DF61380173 for ; Sun, 22 Dec 2024 07:16:51 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Sun, 22 Dec 2024 07:16:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rwec.co.uk; 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=fm2; t=1734869811; x=1734956211; bh=cjLFCDoy74 nD2raWOygvdfvAv3MHYcSgZph82bmMax4=; b=ncC8x8Ml4a3KsNrTIfhzPquR1a pHOAD276wi00+2asM+UQ96V/NAxbudwRZ99iNPIrrHEW5ocfzFfRyxlfAciRqxkH xWX1ettTbuTNse+IMiFkocavZthtb+xbE6f6RNfKLe1I28H/fXYOZn8nJDwdsjuo jrbUya7enmZLiUNSPi7XML4AWydkM8oOe9E5FuL5pwkAJavsApGvJjdwCA6FH5Ki vqdaBOYw/wfWKFJsjAD6X+vX99TQMNrSyczM4p5REyID5O4oI2zX5w+QHCUzOgws 36akvGwcaRlW3LMJ4GgKIZJ68aGhbwVUY0iyErnAwr+aLn4c6ol0eeUmeDOw== 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=fm2; t= 1734869811; x=1734956211; bh=cjLFCDoy74nD2raWOygvdfvAv3MHYcSgZph 82bmMax4=; b=LfFO+BjNQtNNNaSEznqAGgJtHB9EchIOazvbwFjcvrgE52Nlvfc jTQualAmr7aEySghgh9FKN+0bt9+s91wP+qKRfpJAnsJTo4CsAY69KVAcI5A/u++ 2VhPdJu97dpX8rri6llBFw+F/hssxSqjK4OOVs5wlMmitn3mwAqBh7fh93OTdEcR +vKNcr7Dc54MO3Oi3RtPafoX1QLZxCBv+0At2HoR7FkHVN71uu8I1PbTJQ11ZK09 c2KzsSDkiMn8ob8To8Vm+Di7f+C6NfrdGraglLvybWCvPyzp81+fzxBXk6/Iklgi UVSjrqEHY4rgWSCa5Nqv7c+uZjDRyHHsj1A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddruddtkedgfeekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpegtkfffgg gfuffvfhfhjgesrgdtreertddvjeenucfhrhhomhepfdftohifrghnucfvohhmmhhinhhs ucglkffoufhorfgnfdcuoehimhhsohhprdhphhhpsehrfigvtgdrtghordhukheqnecugg ftrfgrthhtvghrnhepheetleeiiefgueduieeuieffvdevheduueefkeejuefgffeftdei tdegtedtleetnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrh homhepihhmshhophdrphhhphesrhifvggtrdgtohdruhhkpdhnsggprhgtphhtthhopedu pdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehinhhtvghrnhgrlhhssehlihhsth hsrdhphhhprdhnvght X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Sun, 22 Dec 2024 07:16:51 -0500 (EST) Content-Type: multipart/alternative; boundary="------------qJzVP1LXXQhA60EJK3676iav" Message-ID: <22132ea8-9e5b-4688-9bf4-4a1972e347b1@rwec.co.uk> Date: Sun, 22 Dec 2024 12:16:48 +0000 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] Discussion: Remove file statcache? To: internals@lists.php.net References: <27531d9d-9bfe-4acc-b9ab-80b1017e3038@app.fastmail.com> <21dd9ac7-e81b-4509-bfa4-a36d05237270@gmail.com> <614d3f45-0f54-4a2e-a21e-2eec5f496fa0@gmail.com> Content-Language: en-GB In-Reply-To: <614d3f45-0f54-4a2e-a21e-2eec5f496fa0@gmail.com> From: imsop.php@rwec.co.uk ("Rowan Tommins [IMSoP]") This is a multi-part message in MIME format. --------------qJzVP1LXXQhA60EJK3676iav Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 21/12/2024 20:50, Niels Dossche wrote: > Adding a parameter for a cache, which should've been transparent in the first place, to every file operation is messy. I would say it's less messy than having to work out when to turn a global setting on or off. In particular, it would be horrible for shared libraries, the equivalent of the above would be something like this: $old_cache_setting = ini_set('enable_stat_cache', 1); $perms = fileperms($name); $size = filesize($name); ini_set('enable_stat_cache', $old_cache_setting); Similarly, for the false case, library code would either have to assume the cache might be enabled, and call clearstatcache() just in case; or it would have to carefully wrap code in similar ini_set blocks. As far as I can see, both code that benefits from the cache, and code that suffers from it, is very rare; but if you know you're writing one or the other, having an explicit way to mark *that code* seems more appropriate than toggling a global setting. > But if you want to add extra parameters to functions that can potentially touch the stat cache, then you need to take into account spl as well. Adding extra parameters to the functions in those classes are a BC break because the signature of potential userland function overrides would no longer be compatible at compile time. Ah yes, I hadn't thought of objects being affected. On the other hand, objects have an obvious place to store both the state of the setting and the cache itself: on the instance. For example, a local rather than global cache would allow this to make two stat calls, rather than four: $file1 = new SplFileInfo($name1, usecache: true); $file2= new SplFileInfo($name2, usecache: true); if (     $file1->getSize() !== $file2->getSize()     || $file1->getMTime() !== $file2->getMTime() ) { ... } In fact, it would probably be useful to pre-fetch a snapshot in the constructor, rather than just caching on the first method call, so that this worked: $before = new SplFileInfo($name, snapshot: true); do_something(); $after = new SplFileInfo($name, snapshot: true); if ( $before->getSize() !== $after->getSize() ) { ... } Inheritance of constructors isn't restricted, so that would not be a BC break, and seems both more powerful and easier to understand than the current feature. Regards, -- Rowan Tommins [IMSoP] --------------qJzVP1LXXQhA60EJK3676iav Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
On 21/12/2024 20:50, Niels Dossche wrote:
Adding a parameter for a cache, which should've been transparent in the first place, to every file operation is messy.


I would say it's less messy than having to work out when to turn a global setting on or off. In particular, it would be horrible for shared libraries, the equivalent of the above would be something like this:

$old_cache_setting = ini_set('enable_stat_cache', 1);
$perms = fileperms($name); $size = filesize($name); ini_set('enable_stat_cache', $old_cache_setting);

Similarly, for the false case, library code would either have to assume the cache might be enabled, and call clearstatcache() just in case; or it would have to carefully wrap code in similar ini_set blocks.

As far as I can see, both code that benefits from the cache, and code that suffers from it, is very rare; but if you know you're writing one or the other, having an explicit way to mark *that code* seems more appropriate than toggling a global setting.


But if you want to add extra parameters to functions that can potentially touch the stat cache, then you need to take into account spl as well. Adding extra parameters to the functions in those classes are a BC break because the signature of potential userland function overrides would no longer be compatible at compile time.


Ah yes, I hadn't thought of objects being affected. On the other hand, objects have an obvious place to store both the state of the setting and the cache itself: on the instance.

For example, a local rather than global cache would allow this to make two stat calls, rather than four:

$file1 = new SplFileInfo($name1, usecache: true);
$file2= new SplFileInfo($name2, usecache: true);
if (
    $file1->getSize() !== $file2->getSize()
    || $file1->getMTime() !== $file2->getMTime()
) { ... }


In fact, it would probably be useful to pre-fetch a snapshot in the constructor, rather than just caching on the first method call, so that this worked:

$before = new SplFileInfo($name, snapshot: true);
do_something();
$after = new SplFileInfo($name, snapshot: true);
if ( $before->getSize() !== $after->getSize() ) { ... }


Inheritance of constructors isn't restricted, so that would not be a BC break, and seems both more powerful and easier to understand than the current feature.


Regards,

-- 
Rowan Tommins
[IMSoP]
--------------qJzVP1LXXQhA60EJK3676iav--