Just today I was challenged with a project that will require value caching in a PHP/MySQL cluster environment. This project will have to deal with loads of up to 500 requests per second, most of which will involve writes. When working on a small scale it is easy to forget the latency issues associated with all engines in MySQL. This project will require a massive read/write caching system that will sit between PHP and MySQL and will require full data persistence. I found a valuable article that shows some of the timing differences of the popular storage systems under load. Redis seems to be the real winner here. With write-only data persistence (write to disk), this storage engine still comes out on top! This is truly the best system if you are caching write calls to MySQL. This way, most of the data will survive in case of a crash. Persistence can be increased even further by using another fully redundant Redis server. This is a must have for high-load write caching.
LDAP authentication through PHP can be quite handy. With methods such as this, authentication can be done against an LDAP user database. This is convenient if you are writing software that you would like to interface against an established user platform. I ran into this writing software for Northern Illinois University that had an established staff and student user database with set password management and user information through Novell.
One of the requirements was the connection had to be through a secure tunnel. So using Apache, PHP, php-ldap module, OpenLDAP and OpenSSL on Fedora Core 5 I was able to do this.
The system started with the Apache, PHP and the php-ldap module installed. A custom configure of OpenLDAP had to be done. I downloaded the newest version from the site and configured and installed it with –with-tls –enable-slapd. After installing OpenLDAP, I had to add the line TLS_REQCERT never to the end of /etc/openldap/ldap.conf. This option may be needed if you are having certificate troubles.
The following are the two functions i used in PHP to actually do the authentication.
function ia_ldap_search($ds, $user) {
$sr=ldap_search($ds, “o=NIU”, “cn=$user”);
$info = ldap_get_entries($ds, $sr);return $info[0];
}function ldap_auth($user, $pass, $search=false) {
$ds=ldap_connect(_IA_STREAM);if($search) {
$info=ia_ldap_search($ds, $user);
$user=$info['dn'];
} else $info=$user;$r=@ldap_bind($ds, $user, $pass);
ldap_close($ds);return $r ? $info : 0;
}
_IA_STREAM is a define I provided previously that is the URI of the LDAPS server (ldaps://host:636). These two functions should provide you with the basics from LDAP authentication over SSL. The ldap_auth function takes the username and password and returns the user info if validated, or 0 for failed. Username search can be done by providing the username and settings $search to true when calling the function.
It’s nice to be able to change the default thumbnail size for image uploads in Wordpress. I upload tons of big pictures and it’s nice if the thumbnail just fits within the content width. So here is an easy way to make this change in Wordpress. They have introduced the wp_thumbnail_max_side_length filter that can be used to change the default size in plugings and so forth, but this is far easier.
Navigate to your wp-admin folder in your Wordpress installation. Edit admin-functions.php and head to line 2228. You should find this line:
$max_side = apply_filters( 'wp_thumbnail_max_side_length', 128, $attachment_id, $file );
The default max size is 128px. You can choose what you want for this now. This size determines the maximum size of any side of the image. For my template though, I only care about width. I always want the thumbnail to be as wide as the template. To make that change, go to line 2276 of the admin-functions.php file. Change the following line:
if ( $image_attr[0] > $image_attr[1] ) {
To:
//if ( $image_attr[0] > $image_attr[1] ) {
if (1) {
That’s it! Now Wordpress will always scale the thumbnail according to the width. Save your changes and try em out.