Thanks for those tips.
The main problem is that the code works most of the time. I don't understand how it would be possible to work most of the time if there were actual problems with the syntax or module incompatibility.
I thought it might be related to load but I have been monitoring the server load and the errors do not correlate with that either.
I'm a bit lost as to how to actually fix this as I have around 200k lines of code to go through.
The site is running on debian squeeze and is in production. I can fix incompatibilty issues if they are logical but random inconsistent errors that don't correlate is pretty tough.