Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117598 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 68955 invoked from network); 25 Apr 2022 11:26:45 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 25 Apr 2022 11:26:45 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 535F6180539 for ; Mon, 25 Apr 2022 06:01:45 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-yb1-f182.google.com (mail-yb1-f182.google.com [209.85.219.182]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 25 Apr 2022 06:01:45 -0700 (PDT) Received: by mail-yb1-f182.google.com with SMTP id i38so7870582ybj.13 for ; Mon, 25 Apr 2022 06:01:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=+vek56B0tqLSz5DkS2TgVn7YfLd6ieoHITRhc5EVt6o=; b=LVDZni+bR/FyK6GybsE03v2fEbuH+HoEFQ1igd0Te1GT9q5HW/ty1X+XBFkdo8IKWC WVq6dwl+ncd3/+6+6Wksx1JToh+MXOrcvWUoM0xWHlPjYesQxHzE/K7IQLhsEbcSMac3 WJ5ZCmCkml8YiEFgB9QSSvvprYiNHfnK1BggCuRjROlN96tHDEXctfc7e9/kVMS73Nh9 7c3mGG79t9HLPoP7Hh8US3j7z0RNIwEuS4PrVccLYAT6s2xwYArFu6ohEPM0rYt8G3ng NJDPi2JO9p+1zWbwZv1vvgfpw8w6jJIIA6JZsMnlOexAmD1sQ4qcIX15WHHwDnEknZiK Ydhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=+vek56B0tqLSz5DkS2TgVn7YfLd6ieoHITRhc5EVt6o=; b=Qsdb8CzYiAijxxd1DmuECdkvAFJro4CV+pgEgNJxNedysWTba+ifdM9V3NDWFd0wDf j0z/ogLhmPxYAPFV8r+J2FL4fARTc95PqCoEWe4M+3ZRrBI8GwjL6nmrfkuBwTTK1Tkk mCqvTDgY1n7mpAsKSkQmNxOEAsXfxoAtr3/0SRKrZisKDb0fvxan9Ko6ZWtt3Q2u6hi+ 2CvC9HO+HD97wYbdIfcMyLNJtsNjhCBIDdLrHRlgN5f82sBB4sF/JWuL2TPXnCulY063 22LfSBwdffUi2dFgJ0ugh4xTvKzay0py5kB53LysTethIliw3tl10N0glRMjj8bwOrOK U0/A== X-Gm-Message-State: AOAM531GUEg5biUfL806rj/8jGQo1qbkVJS6bC+O1qpdmqqjGbbYexjK s/T6uSdtDPcb9ihsFMKNAP5wNRXGsybc/OYSuQ== X-Google-Smtp-Source: ABdhPJx5bRZTvNyKgyanWcZQbHzK0PM8fgqYzVgXZ1Yp8jnUUvXhYcAvvmJEMmmYEUaGUSpXyYwU4/ZVbSwfG8vhJr8= X-Received: by 2002:a25:a148:0:b0:641:d14b:ddd3 with SMTP id z66-20020a25a148000000b00641d14bddd3mr16367918ybh.402.1650891704460; Mon, 25 Apr 2022 06:01:44 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 25 Apr 2022 15:01:35 +0200 Message-ID: To: Hans Henrik Bergan Cc: PHP internals Content-Type: multipart/alternative; boundary="0000000000009b681f05dd7a2d74" Subject: Re: [PHP-DEV] Re: LOCK_SH for file_get_contents ? From: guilliam.xavier@gmail.com (Guilliam Xavier) --0000000000009b681f05dd7a2d74 Content-Type: text/plain; charset="UTF-8" First, hello... > This has been requested for years (since at least 2009?) but it seems no > > actual plan has been proposed > > How about this? > > since we already have the constant FILE_USE_INCLUDE_PATH , seems it was > > introduced in PHP5.0.0, > > > > 1: FILE_USE_INCLUDE_PATH currently collides with LOCK_SH (they're both > 1), > > lets change FILE_USE_INCLUDE_PATH to something that doesn't collide with > > any of LOCK_SH | LOCK_EX | LOCK_NB > > for example (1 << 3) / int(8) > > 2: change argument #2 from "bool $use_include_path = false" to "int|bool > > $flags = 0" , treating bool(false) the same as int(0) and bool(true) the > > same as FILE_USE_INCLUDE_PATH , and support LOCK_SH | LOCK_NB | > > FILE_USE_INCLUDE_PATH here > > (i think LOCK_EX could also be supported, but that might be > controversial, > > and the use case is certainly limited, if there is one at all) > > > > because it's kind of silly, and at times annoying, that file_put_contents > > support LOCK_EX but file_get_contents does not support LOCK_SH > > can we at least change FILE_USE_INCLUDE_PATH to 8 / (1<<3) ? that would > allow a userland implementation of file_get_contents to support LOCK_SH and > FILE_USE_INCLUDE_PATH > > The current situation is so bad that FILE_USE_INCLUDE_PATH literally cannot > be used in strict_mode=1, it's pretty much completely useless since php > 7.0, so I doubt it'll break anything keeping up with new releases of PHP. After some search, I assume you're referring to https://bugs.php.net/bug.php?id=47115 (Request #47115 Can't use flag LOCK_SH in file_get_contents "similar to file_put_contents can use LOCK_EX"). I'm more "empathetic" to that than with your mails alone. Anyway, I doubt FILE_USE_INCLUDE_PATH can be changed to 8, because that's already FILE_APPEND (and both can be used with file_put_contents()). Here's the current (PHP 8.1, unchanged since at least 5.6) var_export() of `array_filter(get_defined_constants(), function ($k) { return preg_match('/^(FILE|LOCK)_/', $k); }, ARRAY_FILTER_USE_KEY)`: ``` array ( 'LOCK_SH' => 1, 'LOCK_EX' => 2, 'LOCK_UN' => 3, 'LOCK_NB' => 4, 'FILE_USE_INCLUDE_PATH' => 1, 'FILE_IGNORE_NEW_LINES' => 2, 'FILE_SKIP_EMPTY_LINES' => 4, 'FILE_APPEND' => 8, 'FILE_NO_DEFAULT_CONTEXT' => 16, 'FILE_TEXT' => 0, 'FILE_BINARY' => 0, ) ``` (ignore the last two). Actually it almost looks like it's only "by chance" that file_put_contents() can use LOCK_EX (2 i.e. 1<<1) together with FILE_USE_INCLUDE_PATH (1 i.e. 1<<0) and FILE_APPEND (8 i.e. 1<<3)... That said, [I don't think LOCK_SH = 1 can be changed, but] maybe FILE_USE_INCLUDE_PATH can be changed to e.g. 32, along with your suggestion 2 (change argument #2 [of file_get_contents()] from `bool $use_include_path = false` to `int|bool $flags = 0` [*but*] treating `true` like FILE_USE_INCLUDE_PATH [*rather than 1 i.e. LOCK_SH*] [note sure about LOCK_NB though])? (PS: there's also **file()**, which currently supports FILE_USE_INCLUDE_PATH, FILE_IGNORE_NEW_LINES and FILE_SKIP_EMPTY_LINES...) Regards, -- Guilliam Xavier --0000000000009b681f05dd7a2d74--