note 112334 added to wrappers

From: Date: Mon, 03 Jun 2013 04:46:26 +0000
Subject: note 112334 added to wrappers
Groups: php.notes 
Request: Send a blank email to php-notes+get-195033@lists.php.net to get a copy of this message
The use of php://temp/maxmemory as a stream counts towards the memory usage of the script; you are not specifying a new memory pool by using this type of stream. As noted in the documentation however, this stream type will start to write to a file after the specified maxmemory limit is exceeded. This file buffer is NOT observed by the memory limit. This is handy if you want your script to have a reasonably small memory limit (eg 32MB) but but still be able to handle a huge amount of data in a stream (eg 256MB) The only works if you use stream functions like fputs(); if you use $buffer .= 'string'; or $buffer = $buffer . 'string'; you're calling your stream data back into PHP and this will hit the limiter. As a practical example: <?php // 0.5MB memory limit ini_set('memory_limit', '0.5M'); // 2MB stream limit $buffer = fopen('php://temp/maxmemory:1048576', 'r+'); $x = 0; // Attempt to write 1MB to the stream while ($x < 1*1024*1024) { fputs($buffer, 'a'); $x++; } echo "This will never be displayed"; ?> However, change fopen to use php://temp/maxmemory:1 (one byte, rather than one megabyte) and it will begin writing to the unlimited file stream immediately, avoiding memory limit errors. ---- Server IP: 69.147.83.199 Probable Submitter: 120.151.150.174 ---- Manual Page -- http://php.net/manual/en/wrappers.php Edit -- https://master.php.net/note/edit/112334 Del: integrated -- https://master.php.net/note/delete/112334/integrated Del: useless -- https://master.php.net/note/delete/112334/useless Del: bad code -- https://master.php.net/note/delete/112334/bad+code Del: spam -- https://master.php.net/note/delete/112334/spam Del: non-english -- https://master.php.net/note/delete/112334/non-english Del: in docs -- https://master.php.net/note/delete/112334/in+docs Del: other reasons-- https://master.php.net/note/delete/112334 Reject -- https://master.php.net/note/reject/112334 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#195033) next »