Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:119530 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 55126 invoked from network); 12 Feb 2023 15:03:05 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 12 Feb 2023 15:03:05 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 551F818033A for ; Sun, 12 Feb 2023 07:03:04 -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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) (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 ; Sun, 12 Feb 2023 07:03:03 -0800 (PST) Received: by mail-ej1-f53.google.com with SMTP id lu11so26308553ejb.3 for ; Sun, 12 Feb 2023 07:03:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=kB3sGJkSH2JK7aV+DLBgdI88aYmO69jSghn6scOSFZQ=; b=lXBbCEVpHCebdJ9AMsvNWP+2/kIrE2NbNKStPSCOsvZ39aUI38giAx1MyqCcl3jgO+ oDn9bOmmC81IgFuT2xa0ixHN/XaXRE3YDYMNUTBCMqGkcICecWltukMzAyc46k18Bzo+ m6WiI6TdEtrV3P2GEM8+aOMBnh53zNARzYB38I+LHhsPDqCKe53mUTkvHOMkNBOHXu2d d1MWWlQkytjAnV1cDkGPpIV2fwf8cQSU3nhxn/K7UBbyQkCF8NVcJOHtso8KP3IHxfs1 gAbzLX1EJmItSn0I5ufzNKc9XoDA3X8Yem3/PmBPVudjSzB4tQMsiiFACD3HuLZTpVp0 JP0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=kB3sGJkSH2JK7aV+DLBgdI88aYmO69jSghn6scOSFZQ=; b=Iv5sYvzQUsb+/iQKvdUSNt9psBNOw+hPl+3JGJXH/ND0+3UwAueVPjcCES+WsVi3m8 AxZQCt04PZFMtMhpsqvrRey6UccmYEXjZef/kLrfTg6j7AhYL4jX6ZREXbAuc7Dy7m4s lv71QmTXuf8IzJ/jbFljCpLge9fnd92vSxhWuEc8ldP+CnRQ91ggnDuFmqn8Sfyno9rF oH76eBiKLJXbVaTHApbh17ZDcEKu2Usp0+ZsRIjj31ouWxCiOzBP1ajNpodmOnn/fYeA DwHoHmRilm2PXoi9WoA0xxOSpbxpHlXUy8uap0ndbT29chWHogtTHrbyLlIRL6fU9Jd5 /sBg== X-Gm-Message-State: AO0yUKXqFVEQkA3hYsKa6Inp8vDrzzlRhCto817xa29bprVSzRs3Zv3r EfWAJe9be3L5i+oSchc8qR2jBQrceXQ= X-Google-Smtp-Source: AK7set/fI+YGYiIjdPl1Ampjelb30a9rrhZOndzCfYa5gQtk05Pbhxh8KRpOe0byfXQL2ZiNeYcJlQ== X-Received: by 2002:a17:907:3341:b0:87d:f29:3a16 with SMTP id yr1-20020a170907334100b0087d0f293a16mr20522244ejb.34.1676214182632; Sun, 12 Feb 2023 07:03:02 -0800 (PST) Received: from [192.168.0.104] (178-117-134-240.access.telenet.be. [178.117.134.240]) by smtp.gmail.com with ESMTPSA id h5-20020a170906260500b007aece68483csm5434492ejc.193.2023.02.12.07.03.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 12 Feb 2023 07:03:01 -0800 (PST) Message-ID: <20519296-008b-f387-887b-6f6508de2831@gmail.com> Date: Sun, 12 Feb 2023 16:00:52 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 Content-Language: en-US To: Thomas Hruska , Hans Henrik Bergan Cc: PHP internals References: <518e7f86-c4b6-c4f5-8e99-8a51ce049738@gmail.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] RFC karma request From: dossche.niels@gmail.com (Niels Dossche) On 12/02/2023 15:46, Thomas Hruska wrote: > On 2/12/2023 5:47 AM, Hans Henrik Bergan wrote: >> Fwiw I would also find an $offset argument useful. fpassthru's lack of both >> $length and $offset made my life harder when implementing "HTTP 206 Partial >> Content" / "HTTP range requests", > > I was going to suggest this myself until I realized that an $offset parameter would be rather problematic.  What happens if the offset is negative?  Does a negative offset mean seek backwards from the current position OR start at that many bytes from the end of the stream?  Is the offset a seek operation or a read operation?  Not all streams are seekable and reading is generally a fairly slow, blocking I/O operation.  Also, not all stream lengths are known.  A negative offset in non-seekable scenarios would almost certainly have to throw an error. fseek()/fread() are more flexible and consistent for getting to the desired starting point in a source stream. > A negative offset would not be valid, just like it is not valid for stream_copy_to_stream. The offset is a seek operation just like is the case for stream_copy_to_stream. Not all streams are seekable that's true, but the programmer using the changed fpassthru function would have the same issue if they were to use fseek or stream_copy_to_stream. > A negative $length would also present some issues.  Again, not all stream lengths are known.  Correctly handling negative values would require managing an internally, temporarily allocated buffer of sufficient size to be able to backtrack streams of unknown length.  And might even have to cache the entire stream in RAM, which would be problematic for 1GB+ streams.  Or just throw an error for such streams. Or just restrict $length to non-negative values only. > > In short, a non-negative, nullable $length parameter is the only well-defined operation for fpassthru(). > The behaviour of a negative $length would be the same as for stream_copy_to_stream. The current behaviour for negative lengths < -1 is to interpret them as unsigned lengths. For lengths == -1 the behaviour is to copy everything. I don't see how this is different from for example very large lengths and an unknown stream length. I don't really understand your concern here. Could you please elaborate on the problem you see? > fpassthru() is largely a convenience wrapper around fread()/unbuffered echo in a loop with some extra output buffer management and is subject to PHP max_execution_time.  For large files and/or slow/high latency networks, PHP can timeout before delivering all content. > > There are several web server extensions available (X-Sendfile and X-Accel-Redirect) where, for local files, the rest of the request can be handed off from PHP to the web server to completely avoid writing any file output to the output buffer and also avoid timeout issues.  The existence of modern web server extensions for all major web servers limits the overall usefulness of fpassthru().  IMO, $length should be added for language-level completeness/convenience but it might also be a good idea to mention X-Sendfile/X-Accel-Redirect in the documentation for fpassthru() so that users are encouraged to leverage resource-efficient technologies wherever possible. > I agree it's a good idea to add this to the manual, although it should be noted that not every place where PHP is provided for hosting has this functionality available. > >> Ended up with a >> $output = fopen('php://output', 'wb'); + stream_copy_to_stream() >> hack because of fpassthru's shortcomings (Thanks to cmb for that hack, by >> the way) >> >> >> On Sat, Feb 11, 2023, 15:26 Niels Dossche wrote: >> >>> Dear internals >>> >>> I would like to gain RFC karma for creating and proposing an RFC: >>> "Implement GH-9673: $length argument for fpassthru". >>> Account name: nielsdos >>> >>> Thanks in advance >>> Kind regards >>> Niels > >