Mark Foster's Blog

Misadventures in Technology

Limited screen resolutions running CentOS as a VirtualBox guest

If you are attempting to run a newer version of CentOS as a guest on VirtualBox you need to install the “Guest Additions” on your CentOS VM to enable higher display resolutions. If you don’t, 800×600 and 640×480 will probably be your only options.

This is in the manual of course but if you were in a bit of rush like myself you may have missed that part. ;) Once you complete the “Guest Addition” installation process the CentOS guest desktop will dynamically re-size to match your view-port. Installing the Guest Addition will add some other handy features including a shared clipboard and shared folders.

If you are running an older CentOS guest you may have to manually add additional resolutions to the xorg.conf file.

Php-cgi.exe application error on IIS with FastCGI

I recently installed PHP 5.2.14 on a Windows 2003 machine running IIS 6 with FastCGI to do some PHP testing at home. I chose the fast CGI install and added several extensions during the install including Curl and Oracle. When I attempted pull a test page after the install completed, I saw the following php-cgi.exe application error on the Windows server’s desktop:

The instruction at “0x100f36ec” referenced memory at “0x000c0194″. The memory could not be “read”.

IIS sent the following error message back to the requesting browser after a couple minutes:

FastCGI Error
The FastCGI Handler was unable to process the request.

Error Details:

* The FastCGI process exited unexpectedly
* Error Number: -1073741819 (0xc0000005).
* Error Description: Unknown Error

HTTP Error 500 – Server Error.
Internet Information Services (IIS)

After some trial and error I was able to get my test page to display if I commented the “extension=php_curl.dll” and “extension=php_oci8.dll” lines in my php.ini file:

; Local Variables:
; tab-width: 4
; End:
[PHP_CURL]
;extension=php_curl.dll
[PHP_GD2]
extension=php_gd2.dll
[PHP_MSQL]
extension=php_msql.dll
[PHP_MSSQL]
extension=php_mssql.dll
[PHP_MYSQL]
extension=php_mysql.dll
[PHP_MYSQLI]
extension=php_mysqli.dll
[PHP_OCI8]
;extension=php_oci8.dll
[PHP_PDO]
extension=php_pdo.dll
[PHP_PGSQL]
extension=php_pgsql.dll
[PHP_SHMOP]
extension=php_shmop.dll
[PHP_SOAP]
extension=php_soap.dll
[PHP_SQLITE]
extension=php_sqlite.dll
[PHP_XMLRPC]
extension=php_xmlrpc.dll

After some more trial error I was unable to get PHP to work without leaving the two lines commented. I tried both the VC6 thread and VC6 non thread safe versions and both exhibited the same behavior. On the PHP download page there is a “Which version do I choose?” section that basically explains that I should be using the VC9 version for IIS. Unfortunately I only saw the PHP 5.3.3 VC9 download and I wanted to test with PHP 5.2.14.

I downloaded PHP 5.3.3 anyway and it worked. I guess I will be testing with PHP 5.3.3.

On a somewhat related note, if you are using FastCGI with IIS, you will probably want the VC9 PHP 3.3.3 non thread safe version. This article explains why.

How to get the contents of an Oracle CLOB data field in PHP

The Oracle “CLOB” (Character Large Object) is a data type used to store up to 4 Gigabytes of text. Retrieving the contents of a CLOB is not as intuitive as you might think.

Let’s say you have a CLOB field/column named “mychars” in an Oracle DB table named “mytable” along with some other fields. You want to simply echo out the text in the “mychars” field:

<?php
    $id = '3';
    $conn = oci_connect('myusr', 'mypass', 'mydb');
    if (!$conn){
        echo 'Connection error.';
    }
    $sql = 'SELECT * FROM mytable WHERE myid=:id';
    $stid = oci_parse($conn, $sql);
    oci_bind_by_name($stid, ":id", $id);
    $result = oci_execute($stid);
    if($result !== false){
        while($row = oci_fetch_assoc($stid)){
            echo $row['mychars'];
        }
    }
?>

The above code will give you an error that looks like the following:

Catchable fatal error: Object of class OCI-Lob could not be converted to string in somefile.php on line 14

If you try to do a print_r() on the CLOB in an attempt to figure out what you are dealing with you will get something that looks like:

OCI-Lob Object ( [descriptor] => Resource id #3 )

This is because a Lob object is returned instead of the contents of the CLOB.

To get the CLOB contents you will need to call the load() or read() methods on the returned object. The latter will require the length of data to read in bytes but has the advantage of not being limited by the script memory limit:

<?php
    $id = '24382';
    $conn = oci_connect('myusr', 'mypass', 'mydb');
    if (!$conn){
        echo 'Connection error.';
    }
    $sql = 'SELECT * FROM mytable WHERE myid=:id';
    $stid = oci_parse($conn, $sql);
    oci_bind_by_name($stid, ":id", $id);
    $result = oci_execute($stid);
    if($result !== false){
        while($row = oci_fetch_assoc($stid)){
            echo $row['mychars']->load();
            //or
            echo $row['mychars']->read(2000);
        }
    }
?>

How to reverse the keyhole on a Kwikset Lever so the teeth face up

So let’s say you just purchased a Kwikset entry lever from Lowes. You manage to get it installed and even get the levers in correct orientation. If you are lucky the keyhole will be correctly oriented so you can insert the key with the teeth up. If you are not so lucky, the keyhole will be upside-down so the key goes in with the teeth down.

Allegedly the lock will still work even if the tumbler springs have failed, if the keyhole/cylinder is oriented so the teeth go in up so this is the desirable orientation. The directions included with the entry lever do not tell you how to do this.

Fortunately, Kwikset has a video on their website that shows how to reverse the cylinder. There is a small clip on the cylinder you can push/pry out with a small flat-head screwdriver. You then pull the cylinder straight out, rotate it 180 and then push it back in and re-install the clip.

How to add a custom context menu to a Spark TextArea in Flex 4

There is a current known issue with adding custom context menus on a RichEditableText Spark component:
http://bugs.adobe.com/jira/browse/SDK-23926

This includes the TextArea component. Essentially, any custom context menus will not show up. There is a work around mentioned in the comments for the bug on Adobe’s website but I thought I would re-hash and show an example since this had me a bit stumped.

The work around is to attach the context menu to the TextArea’s TextDisplay object via the “textDisplay()” accessor method. I have created a simple example with source.

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="400" minHeight="200" backgroundColor="#9FA0D4" width="500" height="300"
               creationComplete="init();" viewSourceURL="srcview/index.html">
    <s:layout>
        <s:BasicLayout/>
    </s:layout>
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <fx:Script>
        <![CDATA[
            private function init():void{
                var cm:ContextMenu = new ContextMenu();
 
                var red:ContextMenuItem = new ContextMenuItem('Red',false,true,true);
                red.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, handleRed);
 
                var green:ContextMenuItem = new ContextMenuItem('Green',false,true,true);
                green.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, handleGreen);
 
                var blue:ContextMenuItem = new ContextMenuItem('Blue',false,true,true);
                blue.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, handleBlue);
 
                cm.customItems.push(red);
                cm.customItems.push(green);
                cm.customItems.push(blue);
                cm.clipboardMenu = true;
                textArea.textDisplay.contextMenu = cm;
            }
 
            private function handleRed(e:Event):void{
                textArea.setStyle('contentBackgroundColor', 'red');
            }
 
            private function handleGreen(e:Event):void{
                textArea.setStyle('contentBackgroundColor', 'green');
            }
 
            private function handleBlue(e:Event):void{
                textArea.setStyle('contentBackgroundColor', 'blue');
            }
        ]]>
    </fx:Script>
    <s:TextArea id="textArea" x="161" y="74" text="This is a Flex 4 Spark TextArea.  Right click to see the custom context menu. "/>
</s:Application>