Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117583 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 75392 invoked from network); 24 Apr 2022 08:38:40 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 24 Apr 2022 08:38:40 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id AB8E2180380 for ; Sun, 24 Apr 2022 03:13:23 -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, 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-io1-f45.google.com (mail-io1-f45.google.com [209.85.166.45]) (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 ; Sun, 24 Apr 2022 03:13:23 -0700 (PDT) Received: by mail-io1-f45.google.com with SMTP id i196so13001050ioa.1 for ; Sun, 24 Apr 2022 03:13:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:from:date:message-id:subject:to; bh=Lnoi+7zKH2gFioMSzrjfXA22aCl0CFEXszbe3czhpNA=; b=lLHoKP4Nfjeg1kaxGqO7JobN5AsxIcKcJ8z++vtoXYwaWXF2mO8TwqmlKLcNF1YrSQ XwXcvONLSAzI24bshfduxOUIIv85lMEvxEyWQsTz/gg0LiNp3uYkyu9/077ape60bvWd ie/k/asvnpOKTxqbDKpFEKtHcoE3XJ52YfCsfZYyPTPhRZS8yhj/fBwtWG05Jcky1Chm lCHrSWjKmsCCZDUlEIACIp1LiUqRCjBPFGXvLNlhG7SNcs5GknbQU6Xg/f4mu8n63Yur VkXIl8SwM/W7CVWUGVdNt99iZC01HTwS4wtCoZzK3Xd2mg9NWgZq8Oyjk7U7sn+T8Pn/ qyhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=Lnoi+7zKH2gFioMSzrjfXA22aCl0CFEXszbe3czhpNA=; b=XUJu2AbmRpel7AFt1Ct7CKjfertpfSLIzxC9XOBhkZl4F3tHRj0eztMbur+J2/zyL4 WI/d3dDd8W2IUISRSQgTMZHpxJ1VVrcNf8QPMpMPV3sAE0OdGcMQs5MX7q00OBl7hvCt GDbZBefFgGjhP3fCxhs6P2cljCIaTaUMOwBE3qNVx/OnGTrtPEl4DSzqNMw2Wrs1yEKq qXjVuEQ2RCVWom3/+ajZgWGS+VLQJ8B29rrOaCfczHSRABhSNEBWEPgUhJzFpTwFepyM KFN4ZSVDYFx/7KILNMlsckY1ritaquQsnyFh8CYLNsa3WPRxhMoYjg4TTwCf0exjzljT /ikQ== X-Gm-Message-State: AOAM5337bUKzslEKa1KuUitci7oneKJjbVzHtHs33C5XAxbdCePhqwYv zQeZanF1JVmXBWxX6iseiB/DHCBz7o4hRMboEBWauDSpYtg= X-Google-Smtp-Source: ABdhPJwoaecFHBcDWUV/o6cCOsYh/el21ZVvUzqkunmlNVfRmiOEpoYnDOjRZAiXee8CTde+dsjZcdYJ/mTBBJaO/as= X-Received: by 2002:a6b:d10c:0:b0:641:63b2:9ef8 with SMTP id l12-20020a6bd10c000000b0064163b29ef8mr5243408iob.135.1650795202706; Sun, 24 Apr 2022 03:13:22 -0700 (PDT) MIME-Version: 1.0 Date: Sun, 24 Apr 2022 12:13:12 +0200 Message-ID: To: PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Change the values of the LOCK_* constants From: tovilo.ilija@gmail.com (Ilija Tovilo) Hi everyone The issue was raised that PHPs LOCK_* constants don't match the Unix LOCK_* constants. https://github.com/php/php-src/pull/8429 // Unix #define LOCK_SH 1 #define LOCK_EX 2 #define LOCK_NB 4 #define LOCK_UN 8 // PHP #define PHP_LOCK_SH 1 #define PHP_LOCK_EX 2 #define PHP_LOCK_UN 3 #define PHP_LOCK_NB 4 Essentially, in PHPs binary representation UN doesn't get its own bit, but is instead represented as 0b11. I'm guessing the reasoning was that SH, EX and UN must not be combined, while they can all be combined with NB. This avoids additional error handling when multiple of those bits were to be set. However, this has a downside of making checking of bits harder and different from how you would do it in other languages. https://3v4l.org/41ebV We could update the PHP constants to match the Unix values of those constants. Unfortunately, there seems to be a not insignificant number of usages of flock with hard-coded integer values. https://sourcegraph.com/search?q=context:global+file:%5C.php%24+count:100000+flock%5C%28%5C%24%5Ba-zA-Z0-9_%5D%2B%2C+%5B0-9%5D%2B%5C%29&patternType=regexp (The regex engine of sourcegraph is flaky, but the majority of results are correct) The process of replacing these hard-coded values could be partially automated with a few caveats. 1. The value must be direct ($flags = 1; flock($file, $flags); would not work) 2. The migration script would assume that flock is a global and not local function Overall, I'm not completely sure this change is worth it since flock flags are just passed and not read. Let me know what you think. Ilija