Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:119432 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 90467 invoked from network); 31 Jan 2023 20:46:29 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 31 Jan 2023 20:46:29 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2661F1804AB for ; Tue, 31 Jan 2023 12:46:27 -0800 (PST) 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.7 required=5.0 tests=BAYES_05,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-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 31 Jan 2023 12:46:26 -0800 (PST) Received: by mail-ej1-f43.google.com with SMTP id m2so44867912ejb.8 for ; Tue, 31 Jan 2023 12:46:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:subject:from:to:content-language :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=u0NIY5iukNKIJD6wEduzfquxu/Ic/0/lKtWsDhkuk+U=; b=DeUTuTuHb4KqEWvIioDxf6uCGeQjI3BZgXaOf/9XAnhPMCy8t85TDq7l629YKdQFlQ wmZ20n8M9ps3qya1XuYa9QB2l/6VHCPzJWGaGJlV5j6HIyD+24TQ9xPK1pPMwkvZYa0Y lRju6n6WJr3Vd78ejNKRu6XGRO2Hs7KlpMpXjWQt+BL0BMr7Om6KFLh7BG/EY/HUbTVu WvyLRsY6Hx/lfJkwEa9ctjN7mrA/HsD/ZiJc9+X8Rf7Ubai25AW+qjqZnfLSTpsgeSnY dmfU+A0dd559MBxYep6qvGoD4XLKq8lSGd84GqHq+VEZhn10Rs+8ouUtWymPx9K/pWNn UwFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:subject:from:to:content-language :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=u0NIY5iukNKIJD6wEduzfquxu/Ic/0/lKtWsDhkuk+U=; b=izvKkFDi6qfjuov6Ol9d8S1P0pkk5mlDUVFj8ktRqgsYql6Ue1wLWfwV1z2KZyI7QJ t5J0zv6doS7V3j/jkiZMVBIyG6Z5k7JTT1/Vm5cYo+6f6qa5wTfCcTnIIOhQ5dGjbbFR txGulj2sV6MDWDwSBzckdROVXMKbprCb4NWkmPxm1KE35uvMB5+vHtKNm05wsMSiEyYV AesJ0LL7UZRrSM6MZZVlUeII1Zn99sBpTCxCJ1TCvbDiLnm7zSkJl5Xbuncuky4/GhGe jFAnaaMBWm23/GL3+pmr/B4fpbl2UgtYXr4qXIS5yl5jBLMiavW4y/eYkaVVg+7SONMA xAKA== X-Gm-Message-State: AO0yUKUS6lyojwyJY9Bbvr8BULRbTCdih+7Cd5eZ9otOrsf7cwz+wPvc QS4OjXKKDo1wblvCCTL1/NVbP6MFuxk= X-Google-Smtp-Source: AK7set9u+tn7s6mrugWdI6wloP4+yhYcE/j89bE17EbzGJ4nhJZhrZ8/qOjIepIQSWCIWMNoKtHqgg== X-Received: by 2002:a17:906:f192:b0:878:7ef1:4a20 with SMTP id gs18-20020a170906f19200b008787ef14a20mr18407960ejb.4.1675197985722; Tue, 31 Jan 2023 12:46:25 -0800 (PST) Received: from ?IPV6:2a02:1811:cc83:eef0:7bf1:a0f8:a9aa:ac98? (ptr-dtfv0pmq82wc9dcpm6w.18120a2.ip6.access.telenet.be. [2a02:1811:cc83:eef0:7bf1:a0f8:a9aa:ac98]) by smtp.gmail.com with ESMTPSA id dk2-20020a170906f0c200b00877e1bb54b0sm8930425ejb.53.2023.01.31.12.46.25 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 31 Jan 2023 12:46:25 -0800 (PST) Message-ID: <9ae72882-8498-85f8-af8c-f7591038d56e@gmail.com> Date: Tue, 31 Jan 2023 21:46:24 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Content-Language: en-US To: internals@lists.php.net Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Subject: Proposal to add a $length parameter to fpassthru and friends From: dossche.niels@gmail.com (Niels Dossche) Hey everyone! Recently I came across a feature request for PHP on GitHub issues: https://github.com/php/php-src/issues/9673. In short, this user would like to have an additional *optional* `?int $length = null` parameter to the fpassthru function. Currently the fpassthru function will output every remaining byte of the stream to the output of PHP's process. With a $length parameter you could limit how many bytes of the stream are outputted. For example, if you'd call `fpassthru($my_stream, 3)`, at most 3 bytes will be outputted. Passing null or not giving a $length parameter will result in outputting all the remaining bytes, just like it is the case now. The concrete use-case for the issue reporter is to implement HTTP range requests in a convenient way. The current workaround is to use the stream_copy_to_stream function in conjunction with `php://output` (see the first comment on the GitHub issue). stream_copy_to_stream *does* have a length argument to limit how many bytes are copied. Reasoning: I think that adding an *optional* $length parameter to fpassthru makes a lot of sense because it is analogous with how other functions behave. For example, the fgets, fwrite, fputs, file_get_contents, stream_copy_to_stream and stream_get_contents all have such a length-limiting parameter. The behaviour of $length would be in line with how these functions behave. Scope: There's also the SplFileObject::fpassthru function and the gzpassthru function. Both of these functions would also get the additional *optional* $length parameter to be consistent with the fpassthru function, and behave in the same way. BC: There is one backwards compatibility break unfortunately. If a user made a class that extends SplFileObject and their class has the fpassthru method, they have to change the signature and implementation in order to be compatible with the changed method. Other than that I don't see new issues. Implementation: I already made an implementation of this feature as a PR: https://github.com/php/php-src/pull/10476. Even though there's 220 newly added lines of code, most of the added code is actually in tests. Only a small portion of the added code are changes to PHP itself. Therefore I think that adding this feature is not very disruptive. Questions: My gut feeling says that I probably need to go through the RFC process in order to be able to introduce this feature? In any case, I would like to get feedback on this proposal: - How do you feel about this? - Is this something that you feel is good to add to PHP? - Do you have concerns or objections? Looking forward for replies :) Cheers Niels