Tips and tricks for LAMP (Linux Apache MySQL PHP) developers.
When I cant find a suitable solution to a problem and have to work it out for myself I'll post the result here so hopefully others will find it useful. (All code is offered in good faith. It may not be the best solution, just a solution).
I encountered an issue earlier today whilst trying to process a fairly large (~37MB) XML file through SimpleXML.
It worked just fine on mine and a colleague's development systems but failed with weird errors on the live server, for instance reporting there was "Extra content at the end of the document".
After about an hour of trying to figure it out we realised our dev systems were using libxml v2.6.x and the live server was using 2.7.6. We then read that somewhere between those versions some hard-coded limits were added in that can cause the problem we were seeing.
To get around it you need to specify the LIBXML_PARSEHUGE flag:
$simplexml = simplexml_load_file($file_path, 'SimpleXMLElement', LIBXML_PARSEHUGE);
//OR
$simplexml = new SimpleXMLElement($xml_string, LIBXML_PARSEHUGE);
I'm sure most of you are aware of this but it's something that always takes me a long time to remember.
Whenever you have a seemingly random error on your Linux box - strange MySQL or Apache errors, being unable to write to a file that you could write to a moment ago, etc - always do a quick df -h to check how much disk space you've got left.
This problem is especially evident for those of us developing on virtual machines that often have limited disk space and so can run out easily. A quick recce of your /var/log/ (or equivalent) directory is a good starting point for freeing up space but you may also want to try find / -type f -size +50000k
I spent ages trying to get round this PHP warning today:
"PHP Warning: shell_exec(): Unable to execute '[any bash command]'"
I hadn't changed anything and it was working 5mins before so what was wrong?
A colleague of mine suggested restarting Apache... and it worked!
I don't fully understand why, something to do with Apache running out of resources or something. Anywho, thought it might be useful for someone.