Errors Errors
It was very interesting as my cacti installation began failing today. For no apparent reason. I noticed CPU usage and CPU temperature going through the roof as PHP script ran by cacti was stuck in some infinite loop or active wait state. It seemed to query database non stop without sleeping or anything and it was not doing anything either.
I looked in error log and there was nothing, looked in access log of monitored server ... nothing again. Finally i looked into cacti log and found tons of messages like this:
It is funny how often you can get caught by surprise that PHP is not Java. I have been using type hints in PHP for a long time but somehow i did not came across that for a long time.
If you have a method that type hints the parameter you wont be able to pass null in as in PHP null is not just unknown value but it is also a type.
Just a very short tip as it was a big surprise to me :) If you have xdebug enabled SoapClient will not throw an exception but cause a fatal error.
All you have to do is disable xdebug or make sure that soap service is available.
This is a funny problem that took forever to figure out! unreal!
Friend committed new component into the revision control system i checked it out and my maven builds would get stuck on compilation. It would take like 20 minutes to run the compilation!
Compilation with javac would take forever no matter if there was error or not. Importing any net.xxxx package would make builds stall forever.
There is nothing worse than a PHP Fatal Error :-) Your script terminates immediately and user sees 500 error page (or blank screen if you don't have one).
A nice fatal error i found recently has to do with __toString methods. Apparently there is a exact type check and __toString method in PHP has to return string. If you return something else it will cause exception to be thrown. Even if it would be casted otherwise like if( 1 == '1' ), in toString it has to be real string type.
Unfortunately for us we had some calls to other methods and one of them did not cast to string for integer values. There was no try catch block either so it boubbled up all the way to the top of the stack and caused script to die horribly : -)
I have spent some time trying to figure out the way to set query timeout in mssql and its not easy. Below you can see the process i am using now, unfortunately it does not work with the current PHP mssql extension (to make it work you will need to apply my patch or get latest sources).
Why do you need the query timeouts?
In high availability sites you can not allow any pages to timeout. If there is a problem with the DB (index broken or server overloaded) You still want your customers to see the page on time. It may have banners missing or some footer broken but its still better than waiting 30s and getting a blank page. After 2-3 seconds most users will click refresh button (putting the last nail in your coffin).
From time to time you get some very nasty errors like infinite recursion or infinite loop. Being able to locate the error is crucial to quickly solving the problem.
Here are two tips that can help you find such nasty bugs in PHP code.
It took me a while to notice that one so i write it down for others.
Memcache extension for PHP has a set function that accepts options parameter. Please see details here.
I had strange problem that values were coming back from cache unserialized and i could not figure it out why. After some investigation it occurred to me that config setting of the application was wrong on the server and wrong parameter was passed to memcache set.
Some times you might come across the mysterious web service error in PHP saying: 'Error Fetching http headers'
What it means is that connection or the call itself to the web service took longer than expected. Extensions does not want to wait forever so decides to quit with error.