Blog to discuss Midnight Coders products features, ideas and trends in development of Rich Internet Applications

Monday, September 15, 2008

WebORB for PHP 3.5 (Data Management for Flex plus Silverlight integration)

I am proud to announce immediate availability of WebORB version 3.5 for PHP. This new release delivers a bunch of very cool and powerful functionality.

First, we added support for Data Management for Flex (WDMF). The feature includes a code generator and a runtime environment. The codegen creates client-side (ActionScript) code AND server-side PHP code to do full blown CRUD directly from the Flex client application. Our professional services team have implemented several projects using WDMF and the speed of development is phenomenal. Without writing a single line of code, you get about 90% of the backend code plus a fantastic framework for creating custom data-driven rich client application. You can see a screen cast at the following URL:
http://www.themidnightcoders.com/weborb/php/videos/wdmf/overview

Second, WebORB has always been a client-agnostic technology. We support Flash, Flex, AJAX and now we have added support for Silverlight. The release of WebORB for PHP includes a Silverlight component you can use in your Silverlight application to connect and invoke PHP classes without all the complexity typically involved with Silverlight remoting. All you need to do is to deploy a PHP class into WebORB and the product automatically handles all the marshalling and unmarshalling, type adaptation, etc. We included several examples demonstrating Silverlight talking to PHP using WebORB into the 3.5 product distribution. You can see them all on the Examples tab in the management console. There's also a walk through guide available at:
http://www.themidnightcoders.com/weborb/php/silverlight_and_php.shtm

There are several bug fixes included into the release, so be sure to check WebORB for PHP 3.5 out. If you have any questions about the product, you can post them to the discussion forum. Additionally, we have a knowledge base and for those who wants to receive professional support, check out our support packages.

Friday, September 12, 2008

Running Zend Core with Apache

I just had to go through a rather painful exercise of configuring Zend Core to run with Apache. The initial experience was promising as the installer asked a bunch of questions, but then just hung in the taskbar without a window. The installer has gone far enough to actually download and install the Apache server on my system. However, it didn't get to the point to configure the Apache web server to handle the execution of the PHP scripts. I went through the pain of figuring it out, so if you're in the similar situation, read on as the resources on the web are very scarce and Zend does not publish any clear instructions on how to configure their product to run under Apache. The instructions assume that you accepted all the default values during the installation (specifically the installation path - C:\Program Files\Zend)

  1. The Apache web server uses httpd.conf configuration file. The file is located in C:\Program Files\Zend\Apache2\conf. Open the file and add the following configuration (does not matter where, I added at the bottom):

    LoadModule zend_enabler_module "C:/Program Files/Zend/Core/modules/apache2.2/zend_fcgi.dll"
    FastCgiConfig "C:/Program Files/Zend/Core/etc/fastcgi.conf"
    AddHandler fastcgi-script .php .php3 .phtml .inc
    AddType application/x-httpd-php .php .php3 .phtml .inc
    <Location>
    Order deny,allow
    Allow from all
    </Location>
    Alias /ZendCore "C:/Program Files/Zend/Core/GUI"


  2. The configuration above references application/x-httpd-php mime type, which should be registered in mime.conf located in the same directory as httpd.conf (C:\Program Files\Zend\Apache2\conf). Add the following line in mime.conf:

    application/x-httpd-php php php3 phtml inc

  3. There is a reference to fastcgi.conf in the configuration added in step 1. I am not familiar with FastCGI, so it was the biggest pain to find a sample for that file as Zend does not provide one. Create a text file with the name fastcgi.conf in the following directory C:\Program Files\Zend\Core\etc. The file must have the following content:

    Server type="application/x-httpd-php" CommandLine="C:\Program Files\Zend\Core\bin\php-cgi.exe" ConnectionTimeout="240" RequestTimeout="360" StartProcesses="16" Impersonate="1" SetEnv="PHP_FCGI_MAX_REQUESTS=10000" SetEnv="PHP_FCGI_CHILDREN=1" SetEnv="PATH=?" SetEnv="TEMP=C:\Program Files\Zend\Core\temp" SetEnv="OS=?" SetEnv="SystemRoot=?" SetEnv="ComSpec=?" SetEnv="DB2INSTANCE=?"
    MinDynamicServers 8
    MaxDynamicServers 32
    IpcDir "C:\Program Files\Zend\Core\temp"


    IMPORTANT: For the configuration shown above, make sure the file has only FOUR lines: one that starts with "Server", followed by "MinDynamicServers", "MaxDynamicServers" and "IpcDir". So all the line breaks in the "Server" line must be removed, otherwise configuration processing will fail.

  4. The document root for your PHP code is C:\Program Files\Zend\Apache2\htdocs. If you are deploying WebORB, this is where the zip file must be extracted to. To test if PHP is working, place a test script (call it test.php) with phpinfo() into htdocs. Start (or restart) the Apache server and load it from http://localhost/test.php
    Here's a sample of test.php:

    <?php
    phpinfo();
    ?>

  5. Finally configuring php.ini requires a few extra steps. It is still a mystery for me what algorithm PHP/Zend uses to locate php.ini, but generally speaking copying it to your /Windows directory works. Notice that php.ini that comes with Zend does not enable any extensions, so you'd have to do it by yourself.
If you had a similar experience configuring your system with Zend and Apache, I'd be interested to hear how it went.

The really cool news though is that WebORB runs absolutely flawlessly under Zend Framework, including service browser, test drive and our brand new data management implementation.

Monday, September 08, 2008

Debugging PHP code when invoked from Flex

Among thousand other things we have been doing quite a bit of work on WebORB for PHP lately. One of the most unpleasant things in PHP is the complete lack of normal debugging tools (at least I could not find any decent debuggers that would work for me). As a result, when PHP is invoked from a rich client like Flex, one must get very creative in order to tap into the PHP invocation flow and debug it. The reason traditional echo() does not work is it would mess up the binary output created by the gateway. There are several techniques I found to be very effecive. Below is the full list:

  1. Use native PHP logging. PHP has fairly rich system for error reporting which could be used to log any kind of messages (not just errors). It is important to make sure that your PHP process (or the process running PHP, like IIS/ISAPI for instance) have enough permissions to write to files. Then modify your PHP.INI and enable the following properties: (you can find out where your PHP.INI is by running a PHP page that executes phpinfo())
    log_errors = On
    error_log = C:\some-directory-path\errors.txt
    Once you changed PHP.INI, restart your PHP process and you should be able to log your own errors. There's a function that lets you do that: error_log. For instance, the following line will save a string in the error log file:

    error_log( "yo, log this message",  0 );
    To get a detailed view of a complex type or an array, use print_r, but make sure to pass the second parameter to capture the value. For instance:

    $a = array ('a' => 'apple', 'b' => 'banana', 'c' => array ('x', 'y', 'z'));
    error_log( "contents of the array are " . print_r($a, true), 0 );


  2. Use WebORB Management Console. The console has a feature called Test Drive. Once you deploy your code into the /services folder, you will see your class in the Management > Services tab. Locate the class, expand it and select the method you want to invoke. You will be able to enter argument values right on the screen and invoke the method using the "Invoke" button.

  3. Use Charles or ServiceCapture proxies. Either one of these tools is a MUST for anyone developing an RIA. You can see all the traffic between your rich client running in a browser and the server. Moreover, the tools decode the binary traffic and display invocation and response structures in a tree view format. If you are getting Channel Disconnected error, make sure to inspect the server (PHP) response with one of these tools. (I should probably repeat that 10 times, so it is implanted into the brains of Flex/PHP developers).

  4. Use WebORB logging. WebORB logging provides more granular control over what gets logged. You can also enable/disable individual loggers in the management console (Management > Server Configuration > Logging). WebORB logging dumps the log messages into a file under /logs folder (located in the weborb installation directory). Using the logging API is fairly straightforward. First "import" the classes using:

    require_once(WebOrb . 'Util/Logging/Log.php');
    require_once(WebOrb . "Util/Logging/LoggingConstants.php");

    Then you can start logging using the following call:

    Log::log(LoggingConstants::INFO, "your message or object here" );

    There are several logging categories available, see Util/Logging/LoggingConstants.php for details. Each category can be turn on/off in the management console.

If you have any tips and tricks for PHP/Flex debugging, please post your comments.

Thursday, September 04, 2008

Data Management for Flex and PHP

We have started private beta testing today for the new release of WebORB for PHP. The new version delivers support for WebORB Data Management for Flex - WDMF. The system includes the following components:
  • Data model designer - you can connect to a database (MySQL or SQL Server) and identify the database and tables to work with. For every table you can preview the table data and manage mappings between columns and property names in the generated code
  • Code generator - creates ActionScript and PHP code to work with your data. You can load records, create, update and delete directly from Flex
  • Runtime environment - there's a rich framework to operate on the data. It supports dynamic functions, loading related records and very soon data synchronization as well.
We put together a video demonstrating WDMF for PHP. You can see it at:
http://www.themidnightcoders.com/weborb/php/videos/wdmf/overview

If you are interested in participating in the beta testing, please send an emial to info@themidnightcoders.com.