Archive for category Linux
mk-parallel-restore Outputs BLOB Data
Posted by jervin in BSD/Mac OSX, Linux, MySQL, Perl on August 1, 2010
Recently I was playing around with the Maatkit tools specifically mk-parallel-dump and mk-parallel-restore for refreshing development database copies with production copies. A problem arises when BLOB data is being displayed on the console and transforming my shell prompt into gibberish and missing the results of the restore. Breaking the restore as soon as the BLOB starts output, it was revealed that I was getting the "Got a packet bigger then 'max_allowed_packet' bytes" error. After setting this variable to a reasonable value the restore went smoothly.
Internal Server Error (500) From Your PHP Application
Recently I was working on a script on a fresh virtual server. The script was pulled from a production server and was being actively used. When I try to run it on the test server, it was mysteriously not working, Apache access_log shows 500 HTTP response code, PHP log_errors is ON,even display_errors is set to ON but there were no errors being displayed or logged. Thoroughly deducing my .htaccess, Apache virtual host configuration and doing a sanity check on the application itself, the mysterious error was being caused by one PHP extension missing, in this case php-ldap.
MySQL Default DATETIME Value – A Quick Rant
Posted by jervin in BSD/Mac OSX, Linux, MySQL, Windows on November 20, 2009
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
Posted by admin in Linux, Networking, Virtualization, Windows on October 28, 2009
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
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
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”?
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
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
Posted by jervin in Application Security, Linux on February 2, 2009
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
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.