Bug->Req #80518 [Opn]: CURLOPT_READFUNCTION stream can't rewind

From: Date: Mon, 06 Dec 2021 15:59:45 +0000
Subject: Bug->Req #80518 [Opn]: CURLOPT_READFUNCTION stream can't rewind
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-238217@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80518&edit=1 ID: 80518 Updated by: cmb@php.net Reported by: malacca42 at gmail dot com Summary: CURLOPT_READFUNCTION stream can't rewind Status: Open -Type: Bug +Type: Feature/Change Request Package: cURL related Operating System: windows -PHP Version: 7.4 +PHP Version: Next Minor Version Block user comment: N Private report: N New Comment: Well, there is actually nothing in the docs[1] that indicates that rewinding the stream would be supported. Thus, changing to feature request. [1] <https://www.php.net/curl_setopt> Previous Comments: ------------------------------------------------------------------------ [2020-12-15 12:48:27] cmb@php.net This is not particularly related to PHP 8.0, but likely did never work (at least it does not with PHP 7.3 and 7.4). It seems to me to make it work, we'd have to introduce CURLOPT_SEEKFUNCTION[1]. > this is very very slow using php8, php7 is fast Please file a separate ticket for this, because it is obviously not directly related. [1] <https://curl.se/libcurl/c/CURLOPT_SEEKFUNCTION.html> ------------------------------------------------------------------------ [2020-12-15 10:37:15] malacca42 at gmail dot com replace CURLOPT_READFUNCTION to CURLOPT_INFILE still has same issue Test script: --------------- $file = __DIR__.'/payload'; $fp = fopen($file, 'r'); $ch = curl_init('http://localhost/server.php'); curl_setopt_array($ch, [ CURLOPT_VERBOSE => true, CURLOPT_CUSTOMREQUEST => 'PUT', CURLOPT_FOLLOWLOCATION => true, // follow location CURLOPT_UPLOAD => true, CURLOPT_INFILESIZE => filesize($file), CURLOPT_INFILE => $fp, ]); curl_exec($ch); curl_close($ch); result: ------------ also got "necessary data rewind wasn't possible" ------------------------------------------------------------------------ [2020-12-15 09:19:20] malacca42 at gmail dot com Description: ------------ CURLOPT_READFUNCTION stream can't rewind Test script: --------------- $file = __DIR__.'/payload'; $fp = fopen($file, 'r'); $ch = curl_init('http://localhost/server.php'); curl_setopt_array($ch, [ CURLOPT_VERBOSE => true, CURLOPT_CUSTOMREQUEST => 'PUT', CURLOPT_FOLLOWLOCATION => true, // follow location CURLOPT_UPLOAD => true, CURLOPT_INFILESIZE => filesize($file), CURLOPT_READFUNCTION => function ($ch, $fd, $length) use ($fp) { return fread($fp, $length); }, ]); curl_exec($ch); curl_close($ch); ---------- the "server.php" is very simple if (isset($_GET['n'])) { echo file_get_contents('php://input'); } else { Header("Location: sever.php?n=1"); http_response_code(307); } Expected result: ---------------- server can read payload after redirect as RFC, entity body will resend after response 307 redirect https://tools.ietf.org/html/rfc7231#section-6.4 but CURLOPT_READFUNCTION function only read once maybe php lost CURLOPT_SEEKFUNCTION option https://curl.se/libcurl/c/CURLOPT_SEEKFUNCTION.html One more thing: this is very very slow using php8, php7 is fast Actual result: -------------- got issue "necessary data rewind wasn't possible" ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=80518&edit=1

« previous php.bugs (#238217) next »