Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:54997 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 62066 invoked from network); 28 Aug 2011 13:29:36 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Aug 2011 13:29:36 -0000 Authentication-Results: pb1.pair.com header.from=christian.kaps@mohiva.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=christian.kaps@mohiva.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain mohiva.com from 178.63.228.54 cause and error) X-PHP-List-Original-Sender: christian.kaps@mohiva.com X-Host-Fingerprint: 178.63.228.54 elvis.mohiva.com Linux 2.6 Received: from [178.63.228.54] ([178.63.228.54:39846] helo=elvis.mohiva.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 08/10-60588-EB24A5E4 for ; Sun, 28 Aug 2011 09:29:35 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by elvis.mohiva.com (Postfix) with ESMTP id 0B20D1D24859 for ; Sun, 28 Aug 2011 15:29:32 +0200 (CEST) X-Virus-Scanned: amavisd-new at mohiva.com Received: from elvis.mohiva.com ([127.0.0.1]) by localhost (elvis.mohiva.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id cERAgs3La0KE for ; Sun, 28 Aug 2011 15:29:30 +0200 (CEST) Received: from [192.168.0.3] (p57B5244C.dip.t-dialin.net [87.181.36.76]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: christian.kaps@mohiva.com) by elvis.mohiva.com (Postfix) with ESMTPSA id BD4911D24858 for ; Sun, 28 Aug 2011 15:29:29 +0200 (CEST) Message-ID: <4E5A42B8.20600@mohiva.com> Date: Sun, 28 Aug 2011 15:29:28 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:6.0) Gecko/20110824 Thunderbird/6.0 MIME-Version: 1.0 To: PHPMailingList Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit Subject: Problems with the stream API From: christian.kaps@mohiva.com (Christian Kaps) Hi, I have some problems with the stream API. The methods stream_tell and stream_seek works not as expected in some cases. Before reading the next lines, please look at the short gist(https://gist.github.com/1176641). First example: $fp = fopen('mfx://test1', 'w'); fwrite($fp, '12345678'); fseek($fp, -1, SEEK_CUR); fclose($fp); // stream_seek: $offset = 7 If you call fseek with the arguments (-1, SEEK_CUR) then the $offset parameter in the method stream_seek is 7. It seems that the internal API takes the written bytes returned by fwrite and then it subtracts the argument (-1) from it before passing it to stream_seek. For the constants SEEK_SET and SEEK_END, the passed value is the same as defined for the fseek call. ----------------------------------- The second example: $fp = fopen('mfx://test2', 'w'); fwrite($fp, '12345678'); fread($fp, 2); fseek($fp, 1, SEEK_CUR); fclose($fp); For this example the stream_seek method gets never be called. The difference here is that fread is called before fseek. ----------------------------------- The third example: $fp = fopen('mfx://test3', 'w'); fwrite($fp, '12345678'); fread($fp, 3); ftell($fp); fclose($fp); For this example the stream_tell method gets never be called. It is documented(http://www.php.net/manual/en/streamwrapper.stream-tell.php) that the stream_tell method is called in response to ftell(). But it seems that this method is only be called internally by the stream API. There exists a Bug report at https://bugs.php.net/bug.php?id=30157 In one of the comments Pierre says: There is no bug but a feature request which seems to be very discutable. So with these words, I start the discussion. Christian