|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2020-12-15 09:19 UTC] 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"
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 17:00:02 2025 UTC |
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"