0

I would like to create a PHP "Out Of Memory" error for testing purposes. Is there an easy way to do this and/or to make PHP use a lot of memory very quickly?

I believe that there are a couple of different scenarios that I'd liek to test, one for if memory_limit is reached and one for if memory_limit isn't reched but the system is unable to allocate more memory. A quick way to make PHP allocate a lot of memory would let me test both.

I realise that the PHP script itself may not be allowed to continue.

I'd like to make the program able to hit a specific amount of memory consumption and then to stay active in memory using all.

I haven't tried all that much just yet. I expect that I could use memory fairly quickly by loading a lot of data from the disk or from the database, but that is likely to take a while.

I'm considering generating a massive string with str_repeat, or creating several and adding them to an array until the memory limit is reached.

I could set the memory_limit very low and use far less memory, but I also want to see what happens when the machine is actually at its memory limit rather than what happens when PHP hits its memory limit.

0 Answers0