How did a php error output get INTO the SQL query..?
The context is: we've just updated the php used on the production server from 5.2 to 5.3 At some point it spawned a horde of E_DEPRECATED errors.
The problem was: somehow, the text of the E_DEPRECATED error got INTO the SQL query, causing a Mysqli exception (specifically, a Mysqli prepare error). The error was emitted in the core library, while the SQL query was generated in a project using the library.
The query became something like:
SELECT foo
FROM some_table
WHERE id IN (1,2,3,4,5
Deprecated: Assigning the return value of new by reference is deprecated in开发者_如何学运维 some_file.php on line NN
Deprecated: Assigning the return value of new by reference is de,6,7,8,9)
The question: how could that happen..?
Really dont know, does you code make use of ob_* functions (like ob_start(), ob_end_flush())?
Or does your code use some custom error handler function? Couldnt be that a variable named into your error handler is used to build that sql query?
Post some code so we can help, instead of wondering!
Are you sure that's all part of the same error message? If you have multiple PHP processes writing into the same log file at the same time, it might be possible for a deprecation warning message written by one process to get inserted in the middle of an SQL error message written by another process.
(In theory, this should not be possible if the logfile is properly opened in append mode and each message is written using a single atomic I/O call, but in practice there are dozens of things that might cause the atomicity assumption to be violated. Technically, that would constitute a bug in PHP, but it may be a hard one to fix reliably under all circumstances.)
The more messages you're logging every second, the higher the risk of this happening is, so "a horde" of new warning messages caused by an upgrade (and probably emitted in dense bursts) is just the kind of thing that could trigger such a coincidence.
精彩评论