You can convert an IP address to an int, and vice versa, with these two MySQL functions. Of course I learned about this after I’d already implemented IP address support using BINARY(4) and my own parser/formatter… now that I have my own implementation I can’t bring myself to let it go, and I worry about support for signed/unsigned 32-bit ints (perhaps my concerns are unfounded..?)
Category Archives: Programming
Ackermann function
I was reminded today of the Ackermann function which is famous in computer science.
Robots HTML META tags
Today I added the Robots <META> tag with noindex, nofollow to my HTML error documents.
PHP HTTP response data
Today I learned about headers_list and http_response_code… yay! :)
PHP fflush
spl_object_hash
Learned about spl_object_hash via Stack Overflow. Provides a unique object id in PHP.
PHP Traits and Grafts
Reading about traits and grafts in PHP: Request for Comments: Horizontal Reuse for PHP, PHP Traits, Using Traits in PHP 5.4 and PHP Traits: Good or Bad?. They mentioned the Diamond Problem.
I learned some new syntax too! E.g.:
return $_instance ?: $_instance = new $class;
The ternary operator as a ‘binary’ operator! Cool! See here for details: Since PHP 5.3, it is possible to leave out the middle part of the ternary operator.
PHP range — Create an array containing a range of elements
Today I discovered the PHP range function…
Running Apache as ME!
On my development machine I want Apache to run under my user id so I can automatically generate files (and have permission to write them).
I configured Apache like this:
root@mercy:/etc/apache2# grep -R www-data . ./envvars:export APACHE_RUN_USER=www-data ./envvars:export APACHE_RUN_GROUP=www-data root@mercy:/etc/apache2# vim envvars export APACHE_RUN_USER=jj5 export APACHE_RUN_GROUP=jj5 root@mercy:/etc/apache2# apache2ctl graceful /var/lock/apache2 already exists but is not a directory owned by jj5. Please fix manually. Aborting. root@mercy:/etc/apache2# chown jj5:jj5 /var/lock/apache2 root@mercy:/etc/apache2# apache2ctl graceful
Easy-peasy!
Wait… that didn’t work. The problem was apache2ctl graceful didn’t pick up the new envvars file, this fixed it:
root@mercy:/etc/apache2# /etc/init.d/apache2 restart
Setting the MySQL timezone per connection
Reading about Setting the MySQL timezone per connection which I had to do like this:
db()->exec( "set time_zone = '+0:00'" );