Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:119529 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 53634 invoked from network); 12 Feb 2023 14:59:36 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 12 Feb 2023 14:59:36 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C05EA1804F2 for ; Sun, 12 Feb 2023 06:59:35 -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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, 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-f176.google.com (mail-yb1-f176.google.com [209.85.219.176]) (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 06:59:35 -0800 (PST) Received: by mail-yb1-f176.google.com with SMTP id s203so6515548ybc.11 for ; Sun, 12 Feb 2023 06:59:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=KFki85ELKkytQKkjKLcxEBMposeFFI2Lb9VTlwh5XV4=; b=W7j1vF2HpdrmXM2FIyYVYmPFpIbvyb54y5BqrvudE4g95DIweGbeFq9q+7BhIqkfIg rCcv28TwUTEhr5qb1PPV8briJRMUXfNedfPyR1R5XBWTr9g55hgfFZCNQM3O3VJuxFAp NmpWcSgVo+v9frmNaN6Er85E8MYCi9b11q4zDbtGT8eHY1AJiKUF5kNfWSBAdCzST6tU V8aYqdy2XqJqMqKc2r7tW+oxa8xgG7nTzmcsUwZQQfzaO/DMHPhsjDyR9pFlIE3Q4M6k CPBjr8CpnDcf1qTsN5YTKdSBW2HQBsZ9byfIRTCO1KW0zYpLh00vw63N1NLgHJm1ubVD UvlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=KFki85ELKkytQKkjKLcxEBMposeFFI2Lb9VTlwh5XV4=; b=GMtd1qYSlxh/lKVzAJfoMcsz21ymECWDM1YDseP7wUMwcxm+JhrCcO+KMSY9OSjNBU mApQQvi6PXT7JD493FqD+UIg3bt7Nc4CNsNydsnznsUMjlBu2UtWPe7rEqS1ZxMCscIG 3q8YWSHyA6t572YswajYsWgL7qCtBhkjwMpPqA5pC0SF7Jvpk2NodLp4WvJwrgSsshAm UJGSIbj/uwZCudB+FiBm65O6VbUAM7PEfHlES1Helk2m72cLtWVarp66CmNjkNoCuIzo Uz9YFWQ4XqwOs5xPUdSfwdrJTenAxn5x/BcmiER7I7cj7t16nT5pLCfnfS6E5cq95S68 fjkg== X-Gm-Message-State: AO0yUKUbMF6fGAg9EPew/oh6Wp98xRPZsOSiDkWICprIcWAKW1cE9/B3 7QIuHApfrkyCzN9ZIvvmyPbUDy4YjR9oefx+p+o= X-Google-Smtp-Source: AK7set+tX3myiKwU4TW35GKUjzZnwuSjoaAt+727zFrPzT3lsDeK76GucG8MWMIUYtYjq1br1cOF9ZVpu7DkZ/cSXvA= X-Received: by 2002:a05:6902:202:b0:870:34ae:5e25 with SMTP id j2-20020a056902020200b0087034ae5e25mr2603305ybs.372.1676213974597; Sun, 12 Feb 2023 06:59:34 -0800 (PST) MIME-Version: 1.0 References: <518e7f86-c4b6-c4f5-8e99-8a51ce049738@gmail.com> In-Reply-To: Date: Sun, 12 Feb 2023 15:59:21 +0100 Message-ID: To: Thomas Hruska Cc: Niels Dossche , PHP internals Content-Type: multipart/alternative; boundary="00000000000086045b05f481fa4e" Subject: Re: [PHP-DEV] RFC karma request From: divinity76@gmail.com (Hans Henrik Bergan) --00000000000086045b05f481fa4e Content-Type: text/plain; charset="UTF-8" Good point, and come to think of it, people wishing to $offset can fseek() before before fpassthru() anyway. Nevermind the $offset thing, it's more trouble than it's worth ^^ On Sun, Feb 12, 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 $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(). > > 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. > > > > 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 > > > -- > Thomas Hruska > CubicleSoft President > > CubicleSoft has over 80 original open source projects and counting. > Plus a couple of commercial/retail products. > > What software are you looking to build? > > --00000000000086045b05f481fa4e--