MySQL Default DATETIME Value – A Quick Rant
Nov0
I was reviewing a year old code which I am adding a feature to. It so happened I came to a familiar issue about having two timestamp/datetime columns, one which should have the CURRENT_DATE / NOW() as default value and the other with an 'ON UPDATE CURENT_TIMESTAMP'. Examine the simple structure below:
CREATE TABLE `stories` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`title` VARCHAR( 255 ) NOT NULL ,
`text` TEXT NOT NULL ,
`creationdate` DATETIME NOT NULL ,
`lastupdate` TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE = MYISAM
When you want to store stories, you would also want to record when it was originally created as well track the last time it was updated. The problem here is that adding a `DEFAULT NOW()` clause will not work for the `CREATE TABLE` query above as it is not supported. So when your insert a new story you will have to explicitly add a `NOW()` function for the `creationdate` row so it will reflect the current date as creation date. This should've been a simple schema functionality, turns out after more than a year MySQL seems to ignore for some reason.
Go on have yourself a read here http://bugs.mysql.com/bug.php?id=27645
How about you, how many times have you have to work around this from your application code?
VMWare: Windows 2003 Host, CentOS 5 Guest – Bridged Networking
Oct0
We would usually just setup a NAT based VM appliance for any new requirement. Most of the time, access is limited to ones desktops. When the need arise for a shared Linux VM on our local Windows 2003 server, the inexperienced may find it trouble setting up the CentOS guest as a reachable application server just like its host OS.
To achieve this, make sure the following items a re true:
- HOST » VMWare » Edit » Virtual Network Editor
- Automatic Bridging - "Automatically choose an available physical network adapter to bridge to VMNet0" is UNCHECKED
- Host Virtual Network Mapping - VMNet0 is mapped to you chosen physical adapter, NOT automatically.
- You can disable NAT, DHCP and Host Virtual Network Adapters
- HOST » Control Panel » Network Connections
- Right click your chosen physical adapter, then Properties. Make sure "VMWare Bridge Protocol" is CHECKED.
- GUEST - Assign an unused static IP, the same network/netmask and gateway that is used on your host's physical adapter.
Other items worth checking when inbound and outbound connections from the guest OS:
- Host firewall
- Guest DNS server settings, resolv.conf.
This checklist should get you up and running with a virtualized development platform with the same network visibility as a physical machine in your office.
FFMpeg-PHP: undefined symbol: php_gd_gdImageSetPixel
Oct3
I was recently updating ffmpeg-php on one of our servers to the latest SVN release of the 0.6.3 branch. On a 64bit CentOS 5.3 with PHP 5.2.11, the extension compiled and installed fine however Apache will not load it and spit out the error below:
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/ffmpeg.so' - /usr/lib64/php/modules/ffmpeg.so: undefined symbol: php_gd_gdImageSetPixel in Unknown on line 0
Surely enough, the GD extension was there, but why is ffmpeg complaining about not finding that shared symbol? Because, ffmpeg is loading first than GD (alphabetically) and such symbol has not been loaded. After adding the GD extension line on top of ffmpeg making sure it loads first the error went away and all is well again.
1280×800 on Dell Inspiron 1501 with Slackware 12.2
Aug0
Finally I got to free up this laptop to be an all around testing machine after I got my wife her new MacBook Pro. Since I'd like a little more education, I decided to get back to Slackware after a couple of years. Install went fine, nothing much has changed, as this what drives the distro and what attributes for it's utmost stability, I am not so surprised.
One problem everytime I install a Linux or BSD variant on any laptop is the widescreen resolution. Except for Ubuntu and Fedora, much of them needs manual intervention to have their native widescreen resolution working on that particular distro, Slackware included.
To cut the story short, if you are installing X server for whatever dekstop manager you intend, the default xorg.conf configuration will not help with the widescreen. Simple really, just run xorgsetup, follow your instinct and startx. You should have your beloved widescreen back.
Do you favor a “LAMP (Linux, Apache, PHP, MySQL) Integrator”?
Aug0
I have been reading on a number of project management articles lately and trends on open source projects. There seems to be a lot of fellow PHP developers who are as well Linux administrators for many server functions inluding HTTP servers like Apache and database administrators like for MySQL. Many of them are certified for one or more while many are jumping between careers that emphasizes one to the other thus gaining essential experiences for each.
Looking at job posts from all over the internet, you should've noticed at one time a PHP gig that requires MySQL administration skills and/or knows their way around Linux. PHP does not come by itself anymore, at least commonly, thus I've thought the term "LAMP Integrator". A quick Google search does not seem to turn much on how to define such, thus I have a simple one.
LAMP Integrator - is a PHP developer primarily using MySQL as data backend with strong Linux administration and Apache tuning skills.
It may sound primitive, I am writing as I am thinking so comments and revisions are welcome.
Image Resize with PHP and ImageMagick Maintaining Proportions
Feb1
There are many examples found on the web on resizing images using PHP while maintaining aspect ratio. However most of them are based on a single maximum dimension i.e. should not exceed a certain size with on either height or width.
I have written the code below that will accept a desired height and width and downsize the source image without exceeding either $maxheight or $maxwidth but still maintain proportions.
Adjust your path to ImageMagick accordingly (/usr/bin/convert)
function resizeimage($source,$dest,
$maxwidth = 200,$maxheight = 160)
{
list($width,$height) = getimagesize($source);
/**
* We need to get both ratios so we can
* find which reduced height and width
* will fix the max allowed dimensions.
*/
$hRatio = $maxheight / $height;
$wRatio = $maxwidth / $width;
/**
* Test Dimensions based on height reduction ratio.
*/
$tHeightHR = $maxheight;
$tWidthHR = ceil($hRatio * $width);
/**
* Test dimenstions based on width reduction ratio.
*/
$tWidthWR = $maxwidth;
$tHeightWR = ceil($wRatio * $height);
if($width < $maxwidth AND $height < $maxheight)
{
echo 'Source already below maximum dimensions: '
. $source . " {$width}x{$height}\n";
return false;
}
if($tWidthHR <= $maxwidth) {
$height = $tHeightHR; $width = $tWidthHR;
}
if($tHeightWR <= $maxheight) {
$height = $tHeightWR; $width = $tWidthWR;
}
$cmd = "/usr/bin/convert -resize {$width}x{$height} "
. "\"{$source}\" \"{$dest}\" 2>&1";
@exec($cmd,$output,$retvar);
if($retvar != 0)
{
echo implode(" -- ",$output);
return false;
}
return true;
}
Stealing your RFID Enabled Cards
Feb0
Security researcher Chris Paget recently drove around downtown San Francisco to clone RFID base Passports and Drivers Licenses using an inexpensive kit of wireless tools. More at theregister.co.uk:
Using inexpensive off-the-shelf components, an information security expert has built a mobile platform that can clone large numbers of the unique electronic identifiers used in US passport cards and next generation drivers licenses.
The $250 proof-of-concept device - which researcher Chris Paget built in his spare time - operates out of his vehicle and contains everything needed to sniff and then clone RFID, or radio frequency identification, tags. During a recent 20-minute drive in downtown San Francisco, it successfully copied the RFID tags of two passport cards without the knowledge of their owners.
http://www.theregister.co.uk/2009/02/02/low_cost_rfid_cloner/
Face Detection with PHP
Jan2
I was enjoying playing photofunia.com a while ago when I got interested on how I can implement such a thing with opensource tools, specifically LAMP. In less than a minute, with "php face detection" on Google I found this.
The headline does say face detection - but what does this mean? Easy said, this article focus on how to find faces on images with PHP. Faces have a certain form and so it is possible to search for it. At the end of the search you will say how many human faces are on the image or better: Where are human faces on my image. This article is not intended to be mathematically.
Intel works on the OpenCV library to search for structures on images. The library is shipped with training files, what was trained with hundrets of photos to detect faces from different perspectives on images and so we can focus on the PHP part.
Get Detailed Information About Particular IP address Connections Using netstat Command
Dec0
I was recently investigating a LAMP application bottleneck. Part of which was to monitor web server entry points during peak hours. Looking into segregate connections and what each clients are actually doing I needed some advanced netstat know-how to get thru my goal, so I stumble upon this one from nixCraft:
netstat command and shell pipe feature can be used to dig out more information about particular IP address connection. You can find out total established connections, closing connection, SYN and FIN bits and much more. You can also display summary statistics for each protocol using netstat.
This is useful to find out if your server is under attack or not. You can also list abusive IP address using this method.
http://www.cyberciti.biz/tips/netstat-command-tutorial-examples.html
FreeBSD NFS Server and CentOS NFS Client
Dec0
We were recently migrating a busy site from an aging FreeBSD 5.4 and we cannot disrupt operations while switching platforms from FreeBSD to CentOS. So part of the plan was to share via NFS media files from the old FreeBSD server to the new CentOS.
Here are the steps that I had to do:
- Modify
/etc/exportsfile to include directories you want shared. Ours look something like this:/usr/home/web01/images /usr/home/web01/swf 192.168.0.4
Notice the two consecutive directories. From the man pages, when mounting two directories from the same mountpoint or filesystem it will go the same line on the exports file or you'll get errors like:
Dec 8 10:20:42 web01 mountd[5900]: can't change attributes for /usr/home/web01/swf 192.168.0.4 Dec 8 10:20:42 web01 mountd[5900]: bad exports list line /usr/home/web01/swf 192.168.0.4
-
Restart service on the server. First stop, nfsd.
/etc/rc.d/nfsd stop
You have to make sure that mountd is stopped as well.
/etc/rc.d/mountd forcestop
Then kill rpcbind, I do this by finding the PID for rpcbind and killing it manually.
ps aux|grep rpcbind
It should return something like:
root 6087 0.0 0.1 4776 1248 ?? Ss 10:28AM 0:00.01 rpcbind
Then do the killing:
kill -9 6087
Then we start these processes in reverse order:
rpcbind /etc/rc.d/nfsd start
Starting nfsd should start mountd as well.
- Verify your exports are properly listed
showmount -e
Should give you something like:
Exports list on localhost: /usr/home/web01/images 192.168.0.4 /usr/home/web01/swf 192.168.0.4
- Now if you use
hosts.allowandhosts.deny, make sure that the NFS client is allowed on the NFS services. We have these on our/etc/hosts.allownfs : 192.168.0.4 : allow mountd : 192.168.0.4 : allow rpcbind : 192.168.0.4 : allow
- Now, before mounting on or CentOS client machine we verify first wether the NFS exports are visible:
rpcinfo -p 192.168.0.3
You should get something like:
program vers proto port 100000 4 tcp 111 portmapper 100000 3 tcp 111 portmapper 100000 2 tcp 111 portmapper 100000 4 udp 111 portmapper 100000 3 udp 111 portmapper 100000 2 udp 111 portmapper 100000 4 7 111 portmapper 100000 3 7 111 portmapper 100000 2 7 111 portmapper 100005 1 udp 861 mountd 100005 3 udp 861 mountd 100005 1 tcp 767 mountd 100005 3 tcp 767 mountd 100003 2 udp 2049 nfs 100003 3 udp 2049 nfs 100003 2 tcp 2049 nfs 100003 3 tcp 2049 nfs - So, our exports are visible we can now mount those shares.
mount -t nfs 192.168.0.3:/usr/home/web01/images /usr/home/web02/images mount -t nfs 192.168.0.3:/usr/home/web01/swf /usr/home/web02/swf
- That should do it, you should be able to see your mount points and browse files within them.
Questions welcome!












