Nightmare of PHP programmer: include_once fails

For a moment it was looking like our project got haunted. Suddenly we started getting errors from the libraries being included twice, function exists and class exits kind of error. First few times it was written off as a “honest” mistake and fixed on spot, but it continued to happen again and again. Of course, it was only showing up on production sites, none of the test sites had this issue. Some digging in the code and pulling hairs out lead to the issue: include_once was failing us. Yes, it was doing include of the same file again! One little detail – that only happened when we used...
read more

PHP ftp_connect causing Segmentation Fault (core dumped)

Pretty strange issue and I had hard time to Google it up, so here you go, fellow PHP developers. PHP script which was doing ftp_connect was failing on some installations with Segmentation Fault (core dumped) message. After quite a bit of time wasted looking for answers why, I found that problem was with the FTP host name having trailing line break. Well, that host name was coming from config and technically only developers had access to it, so looks like we assumed that variable “safe” and were not doing standard checks on special characters. To make things worse that line break is hard to...
read more

Error 400: Size of a request header field exceeds server limit

If you get error like this one Error 400 Your browser sent a request that this server could not understand. Size of a request header field exceeds server limit. That means that your browser is trying to send too much at once. Probably, it’s size of the cookies. The easy way to fix it – delete cookies. Of course, you lose all info in the cookies, but at least you can access site again. If you develop/manage web site and your customers complain of this error message – there are two things to do: Review cookies and limit the size of cookies your application stores in the browser....
read more

SQLSTATE[HY000] [2003] Can’t connect to MySQL server on ‘xxx.xxx.xxx.xxx’ (13)

One of the things I wish I had found in Google faster when trying to figure out why PHP script refuses to connect to remote MySQL server issuing an error SQLSTATE[HY000] [2003] Can't connect to MySQL server on 'xxx.xxxx.xxx.xxx' (13) I am able to connect from local shell, so first thought was if something wrong with recent Zend Framework upgrade, but after a while I figured out that answer is very simple – SELinux was blocking remote connections from PHP scripts executed by Apache web server. The error code (13) at the end of error message means “permission denied”, so that’s...
read more