How to trace PHP errors?

前端 未结 5 479
独厮守ぢ
独厮守ぢ 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:04

    In php you can set your own exception handler and error handler, see also documentation on php.net. When an error occurs you can print backtrace and dump that to file or screen.

    Look at the php functions:

    set_exception_handler()
    set_error_handler()
    debug_backtrace();
    

    Hope it helps, Greetz, Erwin Haantjes

    0 讨论(0)
  • 2021-01-14 02:09

    You can try using PHP Error to get a stack trace for errors.

    0 讨论(0)
  • 2021-01-14 02:14

    That's most likely exactly where the problem occurred - your script is sucking up almost all of the 128megabyte limit, and then the database class tries to allocate a bit more space to read something from the database, the limit gets crossed and the script barfs.

    What are you doing that requires using 128meg of memory?

    0 讨论(0)
  • 2021-01-14 02:15

    You can try using http://www.xdebug.org/

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题