Most memory-efficient way to split a variable sized chunks?
问题 Is there a way to do something like an fread , but on a variable? That is, I want to "read" another in-memory variable 1MB at a time. That way I could have something like this: $data = ... ; // 10MB of data $handle = fopen($data, "rb"); // Need something instead of fopen here while (!feof($handle)) { $chunk = fread($handle, 1048576); // Want to read 1MB at a time doSomethingWithChunk($chunk); } fclose($handle); I have a large binary file loaded into memory, about 10MB. I'd like to split it