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>

SWFObject flashvars, params, and attributes

I have been working with SWFObject a bit lately and was a little confused by how the flashvars, params, and attributes arguments for the embedSWF() function differ from each other and what exactly SWFObject did with them. Based on the documentation, I did a little experiment where I used each and then viewed the generated source using the Web Developer Toolbar for Firefox.

Here is my HTML and SWFObject JavaScript which uses the dynamic publishing method as described in the SWFObject Documentation:

<html>
 
<head>
<script type="text/javascript" src="swfobject/swfobject.js"></script>
</head>
 
<body>
<div id="embedhere">Embed Fail</div>
<script type="text/javascript">
 
	var flashvars = {};
	flashvars.my_flashvar1 = "my_flashvar_value1";
	flashvars.my_flashvar2 = "my_flashvar_value2";
 
	var params = {};
	params.my_param1 = "my_param_value1";
	params.my_param2 = "my_param_value2";
 
	var attributes = {};
	attributes.my_attribute1 = "my_attribute_value1";
	attributes.my_attribute2 = "my_name_attribute";
 
	swfobject.embedSWF("Test.swf", "embedhere", "300", "250", "9.0.0", false, flashvars, params, attributes);
 
</script>
</body>
 
</html>

Here is what the generated source looks like after I load the page in Firefox and SWFObject has done its thing:

<html><head>
 
 
<script type="text/javascript" src="swfobject/swfobject.js"></script>
<style media="screen" type="text/css">#embedhere {visibility:hidden}</style></head><div firebugversion="1.5.0" style="display: none;" id="_firebugConsole"></div><body>
<object data="300x250TestAdAS3.swf" name="my_name_attribute" id="my_id_attribute" type="application/x-shockwave-flash" height="250" width="300"><param value="my_param_value" name="my_param"><param value="clickTAG=http%3A//www.example.com" name="flashvars"></object>
<script type="text/javascript">
	var clickTAG = escape("http://www.example.com");
	var flashvars = {clickTAG:clickTAG};
 
	var params = {
		my_param: "my_param_value"
	};
 
	var attributes = {};
	attributes.id = "my_id_attribute";
	attributes.name = "my_name_attribute";
 
	swfobject.embedSWF("Test.swf", "embedhere", "300", "250", "9.0.0", false, flashvars, params, attributes);
</script>
</body></html>

As you can see the attributes are just attributes to the object tag. The parameters show up inside of param tags with one param tag for each param following the object tag. I would be curious to hear if anyone has used the “attributes” and “parameters” arguments when embedding Flash with SWFObject and for what.

The flashvars argument is the most useful in my case because that is how you can get external data passed into the SWF. I think a lot of folks load in their data into a Flash movie using a separate call to load an XML document. That is the way to go if you are pulling a large amount of data dynamically based on some type of user input.

If you only have a few name value pairs that are not going to change, passing these in during the embed using flashvars is probably the better option. Assigning these values during the embed will save a second round trip you would normally make to get an XML document.

So let’s say you decide you want to pass in a couple key-value pairs to a Flash movie using SWFObject. In the code example above there are two key-value pairs we assign to flashvars: “my_flashvar1” and “my_flashvar1”. Now you will want access these two inside your ActionScript code.

For ActionScript 2 it would look something like this:

trace(_level0.my_flashvar1);
trace(_level0.my_flashvar2);

ActionScript 3 requires another line of code to get to the same place:

var paramList:Object = this.root.loaderInfo.parameters;
trace(paramList["my_flashvar1"]);
trace(paramList["my_flashvar2"]);

A word of caution: When you use SWFObject’s embedSWF() function there are quite a few optional parameters. Be sure that you put a “false” in for optional parameters you don’t intend to use before any parameters you ARE going to use. In the embed example below I want to use the flashvars option but I don’t want to use the option to specify an express install file so I put in a false in that spot. Also, just be careful in general because there are a total of 10 different arguments for the embedSWF() function (including all the optional ones) so it is easy to get them in the wrong order and such.

swfobject.embedSWF("Test.swf", "embedhere", "300", "250", "9.0.0", false, flashvars);

Take a look at the SWFObject documentation for a description of each parameter.

That’s it!