note 76787 added to function.substr

From: Date: Mon, 30 Jul 2007 22:06:52 +0000
Subject: note 76787 added to function.substr
Groups: php.notes 
Request: Send a blank email to php-notes+get-129058@lists.php.net to get a copy of this message
If you need to divide a large string (binary data for example) into segments, a much quicker way to do it is to use streams and the php://memory stream wrapper. For example, if you have a large string in memory, write it to a memory stream like <?php $segment_length = 8192; // this is how long our peice will be $fp = fopen("php://memory", 'r+'); // create a handle to a memory stream resource fputs($fp, $payload); // write data to the stream $total_length=ftell($fp); // get the length of the stream $payload_chunk = fread ( $fp, $segment_length ); ?> Working with large data sets, mine was 21MB, increased the speed several factors. ---- Server IP: 216.235.15.211 Probable Submitter: 204.112.176.136 ---- Manual Page -- http://www.php.net/manual/en/function.substr.php Edit -- https://master.php.net/note/edit/76787 Del: integrated -- https://master.php.net/note/delete/76787/integrated Del: useless -- https://master.php.net/note/delete/76787/useless Del: bad code -- https://master.php.net/note/delete/76787/bad+code Del: spam -- https://master.php.net/note/delete/76787/spam Del: non-english -- https://master.php.net/note/delete/76787/non-english Del: in docs -- https://master.php.net/note/delete/76787/in+docs Del: other reasons-- https://master.php.net/note/delete/76787 Reject -- https://master.php.net/note/reject/76787 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#129058) next »