Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111181 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 78792 invoked from network); 24 Jul 2020 21:59:00 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 24 Jul 2020 21:59:00 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 8A3DB180545 for ; Fri, 24 Jul 2020 13:54:01 -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=0.8 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_NONE,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (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 ; Fri, 24 Jul 2020 13:54:01 -0700 (PDT) Received: by mail-wm1-f42.google.com with SMTP id o2so9352048wmh.2 for ; Fri, 24 Jul 2020 13:54:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=derekbonner-com.20150623.gappssmtp.com; s=20150623; h=from:mime-version:date:message-id:subject:to; bh=45XOfKER41pIxDCn7I20Ee/fPHCjULzM0yXjR4za/iQ=; b=lR7e28TnzsQP6VQfxrvJJQ/zQZQ8czNdMTSK8DaCaWZ/WAFBkeLW+DFQfZq6q0XDwB GvPc3XmBGFd4x+8ZW3r7GNQHyuSd6YIFNs2zRFFZP6mPSIkdghtu4uwF7gedyPlhXmwM prGo1CqjbkgMLRX3VNnUWDAIyH5kMAY4p4Rf2hCiaLY9N4vALK4w0TojiRMyOinBrUVx Yr+kzIFzYa/SH+GIkvFavDmF68PpNvRarIMRS/OO+EkdTXj31zKUDDRgpxbxpl4zpMTt o5pKKs6MyG6VkGhj4c5VcCEHPSHN3jp+YB8uN55QhXW4+gTzifiUijzbOh0Ghq6CUDHH HkkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:mime-version:date:message-id:subject:to; bh=45XOfKER41pIxDCn7I20Ee/fPHCjULzM0yXjR4za/iQ=; b=WKDYvdxz+9zT2iqcP+WZJnhEbEJKpuIn+BykLPOQsRblKrRLpCQmi6CKHi7yTtEQlN 7mtEone1FSwqda1r+B/jhyDcKg5zw5Rr8UlreMCjgj9F2MGcTpmE7ep594XB0AIFSr3k xrprq8CCpf8n7scsdGuLWtD+bdziKzPLoZycOeJGpOcE/NcnhopWtOZlkd82gc6kC2S7 FzJzgfcwt0Ozc3fFs2k3WRz7UmCkYTVfXzLzqyD1MmO7Sn+7f01SNEgbVsqtfYaN9EuD DsQIiemngXTdAJEi5aOuD7vv4+W7tcnm0rH3y+/Jy1/6F43ScWOr9+0pHMb0G4BpmvmT 1Y0g== X-Gm-Message-State: AOAM533j1nQFy/yfUBhA+LIsKot3/QnpJq4OxbtE9OZpEUPXIW/Kv6JH MfzcTfih7p4w1lDQ+yHan0ItYyvXrNGaMjK+BViWN8L7 X-Google-Smtp-Source: ABdhPJwIqQD4e0PLwlV4rtLCJpn4w+OrAAqST4SBN9LX0zriIyhGFlPL52+nb7TKSHZar8ex9ftF3YXedjRZEljD758= X-Received: by 2002:a1c:678b:: with SMTP id b133mr7693182wmc.117.1595624038944; Fri, 24 Jul 2020 13:53:58 -0700 (PDT) Received: from 1058052472880 named unknown by gmailapi.google.com with HTTPREST; Fri, 24 Jul 2020 13:53:58 -0700 MIME-Version: 1.0 Date: Fri, 24 Jul 2020 13:53:58 -0700 Message-ID: To: internals@lists.php.net Content-Type: multipart/alternative; boundary="0000000000000969ee05ab362c54" Subject: Proposal: php.ini environment variable fallback value From: derek@derekbonner.com (Derek Bonner) --0000000000000969ee05ab362c54 Content-Type: text/plain; charset="UTF-8" Currently an environment variable can be specified in the php.ini file. This is useful if you want tune one or two settings in your runtime environment. Where this runs into issues is if you want to do something similar to Juan Terminio[1][2]. I'm proposing a change the php.ini parser that would allow for an extended syntax for environment variables in the php.ini. In this syntax when checking for an environment variable if it is empty the fallback value would be used instead. The original environment variable syntax would remain valid as well. Possible syntax options. I currently do not have a very deep understanding of the current .ini parser so this may make invalid assumptions. * memory_limit = ${PHP_MEMORY_LIMIT:-"default value"} * memory_limit = ${PHP_MEMORY_LIMIT::"default value"} * memory_limit = ${PHP_MEMORY_LIMIT:="default value"} * memory_limit = ${PHP_MEMORY_LIMIT=="default value"} * Potential issue: Adopting a bash-ism This type of environment fallback is common in bash. If adopted it could lead users to think other bash features are also available. To dissuade this I would suggest that the fallback value syntax not appear in any of the default php.ini files. Users must read the documentation and decide if it works for them and add it in their php.ini file. Changes needed in the code Digging through the code I find that two sections would need to be changed, both in Zend/zend_ini_parser.y. I hope to be able to write this code myself but would gladly accept some guidance. 1. cfg_var_ref: Currently TC_DOLLAR_CURLY TC_VARNAME '} would need to be changed to something like TC_DOLLAR_CURLY TC_VARNAME ':-' TC_FALLBACK '}' 2. zend_ini_get_var: I imagine this would require adding a third parameter to the function signature that would be used in the event of a null value when checking the environment. [1] https://jtreminio.com/blog/php-modules-toggled-via-environment-variables/ [2] https://jtreminio.com/blog/docker-php/php-fpm-configuration-via-environment-variables/ I look forward to your feedback. Derek --0000000000000969ee05ab362c54--