Fatal error: Out of memory (allocated 1134559232) (tried to allocate 32768 bytes) in X:\wamp\www\xxx
You are encountering a hard limit on your PHP process because it is trying to allocate memory for an array that exceeds the available RAM assigned to your application server. The error message Fatal error: Out of memory combined with (allocated 1134559232) tells you exactly what has happened: your script has already consumed approximately 1.07 GB of RAM, and even a small request for an additional 32 KB triggered the system's out-of-memory handler.
This scenario is particularly insidious because standard configuration changes like increasing memory_limit in php.ini or setting it to -1 (unlimited) often fail to resolve the issue on specific hosting environments or local setups. When you are running on a 32-bit architecture, such as WAMP Server 32 bits, the address space is fundamentally constrained. A 32-bit PHP process cannot access more than roughly 4 GB of virtual address space, and the operating system reserves a significant portion of that for its own use. If your application tries to exceed the physical RAM available to the WAMP service or hits the hard ceiling of the 32-bit pointer space, simply increasing the memory_limit directive will not work; the allocation request will fail at the OS level.
The root cause in your specific case is loading a multidimensional array derived from a CSV file containing 20,000 rows of long sentences into memory all at once. While reading a CSV seems trivial, constructing a massive nested array structure where each element contains a large string creates a contiguous block of data that can easily spill over the physical limits of a local machine, especially if you are running other applications simultaneously.
The 32-bit Constraint
The most immediate technical barrier is your use of a 32-bit WAMP installation. On a 32-bit system, PHP cannot address more than approximately 4 GB of memory, regardless of how much physical RAM your computer has. If you are running Windows, the OS itself consumes a large chunk of that 4 GB limit. Consequently, if your script attempts to allocate an array that pushes the process above the remaining physical memory or approaches the theoretical maximum for 32-bit pointers, the memory_limit setting becomes irrelevant because the kernel denies the allocation request.
Since you mentioned that changing WAMP versions is not an option, you must accept this architectural limitation and architect your data processing around it. You cannot simply "allocate more memory" in a 32-bit environment if the physical or virtual address space is exhausted.
Streaming Data Instead of Loading Arrays
The solution lies in abandoning the pattern of reading the entire CSV into a multidimensional array before performing calculations. Instead, you should adopt a streaming approach. This involves iterating over the file line-by-line using fopen and fgets, processing each row immediately to extract the necessary data for your calculation, and then discarding it from memory.
By processing rows sequentially rather than loading the entire dataset into $rows = [...], you ensure that your peak memory usage remains constant, regardless of how large the CSV file grows. This technique reduces memory consumption from O(n) to O(1), where n is the number of rows. You can aggregate results (such as sums, counts, or complex calculations) in scalar variables rather than storing intermediate states in a large array.
Configuration Limits and Practical Workarounds
While you attempted to set memory_limit to -1, note that this value acts as an infinite limit relative to PHP's internal accounting but still respects the operating system's physical memory constraints. If your local machine is low on RAM, the OS may start swapping data to the page file, which drastically slows down execution and can eventually trigger fatal errors if the swap space fills up or if the 32-bit limit is hit.
If you are forced to keep the multidimensional array structure for specific logic requirements, consider splitting the CSV into smaller chunks using a tool like Excel or Python before importing them into your WAMP project. Alternatively, if you are working with a framework like Laravel, ensure that your service layer explicitly streams data from storage rather than loading it all at once, as this is a best practice even on 64-bit systems to prevent memory spikes during high-concurrency requests.
Ultimately, the fix requires changing how data enters your application. Stop trying to increase the container size; instead, reduce the volume of data inside the container by processing streams rather than batches.