How to trace PHP errors?

前端 未结 5 488
独厮守ぢ
独厮守ぢ 2021-01-14 01:51

I get the following error:

[23-Feb-2011 19:51:29] PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 512 bytes) in /obj/cla         


        
5条回答
  •  悲&欢浪女
    2021-01-14 02:16

    If you're running out of memory while selecting data from a database, chances are you're trying to grab way too much data at once from the DB and trying to load it all into memory. Does your Database Read() method do something like automagically fetch the data and get it all into a variable for you?

    You should probably consider incrementally processing the data, as an alternative to grabbing it all at once, or work with smaller datasets. On the other hand, if you have the ability to do so and you really need to process so much data at once, you could consider changing the memory limit and increasing it using ini_set('memory_limit', '256M'); to increase it to 256MB, for example.

    See:

    http://php.net/manual/en/ini.core.php#ini.memory-limit and http://php.net/ini_set

    Edit:

    For figuring out the trace of how you got to this point, Xdebug is probably your best bet as far as free solutions are concerned. I'd take a look at: http://www.xdebug.org/docs/execution_trace

    The xdebug.show_mem_delta option will probably be the most beneficial to you for figuring out what's spiking your memory usage when looking at the stack traces.

提交回复
热议问题