I am a novice PHP developer and in the process of learning this great language. I now end up having a script consisting of 1,343,579 lines and when I try to run this I am getting the following:
Fatal error: Out of memory (allocated 269221888) (tried to allocate 536870912 bytes) in Unknown on line 0
I have a same piece of code being repeated 512 times because I am allowing 2^9 different combinations accounting for different Search Options. I am trying my best to minimise memory leak by using unset(), nulling variables and sometimes explicitly calling the gc_collect_cycles().
Would you please let me know whether 1 million line code will simply end up having this memory problem OR I am doing something silly in relation to memory management.
Split up your source into smaller parts and include only what you really need. When you repeat the same thing over and over again, refactor this into a separate function and call it with appropriate parameters.
Without knowing the concrete task, we cannot give more advice.
You can build your query string gradually depending on your conditions