ankane/exceptional-php — Issue #12: Undefined Offset errors reported as exceptional.php errors
Author: tjchambers
Created: 2012-01-19 18:55:25+00:00
State: open

With additional of logging the $data at line 85 in current version of data.php I have located multiple instances which report PHPNotice of undefined offsets: (see example which follows:

Array
(
[client] => Array
(
[name] => exceptional-php
[version] => 1.5
[protocol_version] => 6
)

[application_environment] => Array
(
[environment] => production
[env] => Array
(
[MONIT_DATE] => Thu, 19 Jan 2012 12:23:59 -0500
[T] => regress
[MONIT_HOST] => pro1.local
[PATH] => /bin:/usr/bin:/sbin:/usr/sbin
[PWD] => /www/sp.regress
[MONIT_PROCESS_PID] => 0
[MONIT_EVENT] => Started
[MONIT_PROCESS_MEMORY] => 0
[SHLVL] => 2
[MONIT_PROCESS_CPU_PERCENT] => 0
[MONIT_SERVICE] => SPBackgrounder4
[MONIT_PROCESS_CHILDREN] => 0
[MONIT_DESCRIPTION] => Started
[_] => files/code.sp/miscincludes/SPBackgrounder.inc.php
[OLDPWD] => /www/sp.regress/files/scripts
[__CF_USER_TEXT_ENCODING] => 0x1F7:0:0
)

[host] => pro1.local
[run_as_user] => UNKNOWN
[application_root_directory] => /www/sp.regress
[language] => php
[language_version] => 5.3.6
[framework] =>
[libraries_loaded] => Array
(
)

)

[exception] => Array
(
[exception_class] => PhpNotice
[message] => Undefined offset: 59
[backtrace] => Array
(
[0] => /private/var/hosts/regress/releases/20120119172154/files/except/exceptional.php:71:in `handle_error\'
)

[occurred_at] => 2012-01-19T12:47:15-05:00
)

)

These always report the exception as exception.php:71, with an offset value (like 59 above) which varies. My inference is these are reported during a shutdown, as the context is a CLI based agent that does an exit(1) when it determines that the codebase has been altered and therefore gracefully exists. This exit will cause the MONIT application to detect it is no longer running and restart the CLI based PHP code thereby starting it with freshest source files.

I have 25 of these agents (SPBackgrounder###) CLI processes running and when they exit I get 25 of these reported exceptions.

I could infer that the error_get_last() call is getting some prior undefined offset which was not reported (not sure how likely that is), but with 949 locations where in MY code there is a '$array[$xxx]' style reference where $xxx is a variable and potentially numeric , and not rechecked using array_key_exists() I will have a hard time isolating this if it is from my code.

I would appreciate some guidance on how to track these phantom errors down so that I can eliminate them.