Bug #76268 [NEW]: stream_get_contents fail to seek on streams modified by curl_exec

From: Date: Wed, 25 Apr 2018 14:35:05 +0000
Subject: Bug #76268 [NEW]: stream_get_contents fail to seek on streams modified by curl_exec
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-214889@lists.php.net to get a copy of this message
From: divinity76 at gmail dot com Operating system: linux, debian 10 x64 k4.15.11-1 PHP version: 7.1.16 Package: cURL related Bug Type: Bug Bug description:stream_get_contents fail to seek on streams modified by curl_exec Description: ------------ stream_get_contents fail to seek on streams exclusively modified by curl_exec, the optional third parameter of stream_get_contents is "Seek to the specified offset", and is effectively ignored when the stream has only been modified by curl_exec. my best guess is that libcurl calls fwrite directly, and doesn't update php's own stream->position, and stream_get_contents in turn doesn't call fseek if it's not necessary (presumably to save up on syscalls), and determines if it's necessary by checking stream->positioun instead of ftell (presumably to save up on syscalls), then it calls fread() until EOF, which is where libcurl left it, and thus returns an empty string. Test script: --------------- <?php $ch = curl_init ( "http://gstatic.com/generate_204" ); $h = tmpfile (); curl_setopt_array ( $ch, array ( CURLOPT_VERBOSE => 1, CURLOPT_STDERR => $h ) ); curl_exec ( $ch ); $verbose1 = stream_get_contents ( $h, - 1, 0 ); // empty string fseek ( $h, 0, SEEK_SET ); // a manual fseek fixes it $verbose2 = stream_get_contents ( $h, - 1, 0 ); // the actual CURLOPT_VERBOSE log var_dump ( $verbose1 === $verbose2 ); Expected result: ---------------- bool(true) Actual result: -------------- bool(false) -- Edit bug report at https://bugs.php.net/bug.php?id=76268&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=76268&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=76268&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=76268&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=76268&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=76268&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=76268&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=76268&r=needscript Try newer version: https://bugs.php.net/fix.php?id=76268&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=76268&r=support Expected behavior: https://bugs.php.net/fix.php?id=76268&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=76268&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=76268&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=76268&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=76268&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=76268&r=dst IIS Stability: https://bugs.php.net/fix.php?id=76268&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=76268&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=76268&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=76268&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=76268&r=mysqlcfg

« previous php.bugs (#214889) next »