Category Archives: PHP

Opcache issues resolved for symlink based atomic deploys and PHP-FPM

I recently ran into problems with php-fpm and opcache using symbolic links for atomic deploys. The solution was so simple, use $realpath_root instead of $document_root in your fastcgi config. Thank you nginx, you make me feel all warm and fuzzy inside. fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; fastcgi_param DOCUMENT_ROOT $realpath_root;fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; fastcgi_param DOCUMENT_ROOT $realpath_root; Details below — […]

PHP sendmail 90 second delay on Dotcloud [solved]

For months we have been having upstream timeout issues with our Dotcloud PHP service running nginx and php-fpm.  Amongst other causes, we found that after our instances were up for more than a day, php’s mail function using sendmail was consistantly taking exactly 90 seconds to send an email.  Unacceptable. After going back and forth […]

Upstream timeout issues with nginX + php-fpm + CodeIgniter + gzip + xdebug on DotCloud – [resolved]

We have been using DotCloud as our hosting platform for months now, and overall I have been extremely pleased with their service.  There were some bumps in the road early on while they were still in their beta phase, but things have been running very smoothly for a few months now.  Everything except an uncomfortable […]

mongodb geospatial query example in php with distance radius in miles and km

Recently for a project involving 311 reports in New York city, I had to find a speedy way to query over 3 million records within a certain radius of a latitude longitude point. Mysql is slow for this sort of thing, so I decided to try the data set out with Solr. Solr worked great […]

php mysql collation change script

There are times when we get stuck with bad collations on our mysql tables and we are overwhelmed by having to change them by hand. Well, I have written a php script which will go through all your tables and fields in a database and update them to the collation which works for you. In […]

simple but useful php base object for mysql table interaction

I started a project creating an online game which involved lots of objects and tables. Rather than rewrite the same code over and over, I decided to create a base object in which i could simple extend the base object to work with any mySQL table by simply listing all the fields. Here is the […]

simplexml to array

Sometimes dealing with PHP’s simplexml object can be annoying, and you just wish it was a simple array. There are a ton of functions out there for that, but I’ve found this one works best =) Source: function simplexml2array($xml) { if (get_class($xml) == ‘SimpleXMLElement’) { $attributes = $xml->attributes(); foreach($attributes as $k=>$v) { if ($v) […]

Wack Mac newline character in utf-8

So I had a user come to me with with an error with my WYSIWYG editor in our online website builder. He would save his content, which he had pasted from OSX’s TextEdit program, then try to apply that content to his website. I have a PHP function which escapes new lines and single quotes […]