Archive for April, 2005

PHPEdit 1.2 released with Integrated phpDocumentor frontend

Friday, April 29th, 2005

From the release Announcement:

PHP Documentor integration

PHP Documentor is actually the best solution to generate documentation based on PHP code comments. As more and more of you are using this tool, we have integrated its features inside the IDE providing a front-end to its options. This front-end will be available both as a standalone version and an integrated module.

Download links and information about the IDE’s less important features ;-) are available in the Release notes.

AJAX webcast presentation on May 26th

Wednesday, April 27th, 2005

I’ll be presenting an updated version of the presentation I gave last night at AzPHP as a free webcast for php|architect on May 26th. The major change will be a new technical introduction centered around getting you started with JPSpan and building a simple widget.

The live talk will begin at 1:00 PM EST (10 AM PST, 6PM GMT), space is limited so if your interested you’ll want to sign up today.

AzPHP AJAX Slides

Tuesday, April 26th, 2005

The presentation went pretty good tonight, the turnout was pretty good, lots of new faces.

I kept dropping the wireless connection which didn’t help with showing sample apps, but we recovered pretty well. Anyhow the slides are up take a look, any feedback would be appreciated since i’ll be giving an updated version in another month or so.

Slides for AzPHP Presentation: Building Dynamic Web Applications with AJAX

AzPHP User Group meeting tomorrow

Monday, April 25th, 2005

I’ll be giving the presentation at tomorrow AzPHP user group meeting. The topic is: Building Dynamic Web Applications with AJAX.

I’ll have slides up from the presentation in the next few days.

The meeting starts at 7:00, directions are on the AzPHP Website.

If you live in the Phoenix area I hope to see you there.

Improving JPSpan Performance with an Object Pool

Friday, April 22nd, 2005

Some people commented in my AJAX Hello World with JPSpan article that the JPSpan example app was quite a bit slower. After a bit of testing it does seem that the performance problems comes from each JPSpan object having only 1 XMLHttpRequest object, this means if you use 1 object you can only have 1 outstanding call.

I would like to see this fixed with an pool of XMLHttpRequest objects at the JPSpan level, however im sure this will take some time so I have a solution for you today.

Its a small javascript class that implements a simple autogrowing object pool for the create JPSpan remoting objects. I’ve created an updated version of the JPSpan Hello World app that uses the pool and it seems much faster to me.

To use the pool you just need to include objectPool.js.

Then you just need to setup your pool. You’ll notice that the callback object recieves a reference to its parent remote object, this will be used to return the remote object back to the pool.

When you make a remote call now just get the get the object from the pool first.

Then in the callback when your in the callback method you return the object to the pool. Note that you just pass back a poolId that is set on the object not the entire Object.

Thats it your JPSpan apps are now a lot more responsive (of course this means your hitting the server a lot more).

Full source of updated JPSpan HelloWorld app, Try updated JPSpan HelloWorld app, try old JPSpan HelloWorld app.

Couple notes on the Object Pool.

Its pretty simplistic right now there are a couple things im going to update.

  1. Allow returnObject to take an object back just to make things more fool proof
  2. Add in the ability to limit the pool size and various options if that happens, either performing a function on current objects to recover them or just sleeping for a bit
  3. Adding some maintenance methods to let you get specific objects from the pool

Im also going to investigate a couple things but im not sure if its worth it.

  1. Allowing a pool to contain more then 1 type of object
  2. Adding in a method that checks if the object is ready to be returned to the pool instead of returning them with returnObject

If you think you’ll use this code or have any feedback on the items above let me know.

Great Javascript Library

Wednesday, April 20th, 2005

I’ve been working on a small AJAX image gallery application to use as a demo for my AZphp presentation next tuesday. I got to the point where i wanted to be able to drag some Images around, and while I could write the javascript to do this, I always try google first for a problem like this. Much to my surprise I found nice lgpl library that does everything I need.

It handles draging and droping of element, resizing them, cloning items, and some animation. I just started to scratch the surface but the code looks very well done.

If you know of any other javascript libraries please let me know, with a comment or trackback.

AJAX Hello World with JPSpan

Tuesday, April 19th, 2005

In my AJAX introduction post I talked about SAJAX and JPspan this posts walks you through installing JPSpan and writing the same simple Hello World app as we did in the SAJAX post.

Setting up JPSpan

  1. Download JPSpan: http://prdownloads.sourceforge.net/jpspan/
  2. Extract and copy the extracted folder to somewhere in your include path
  3. Your good to go

Create the JPSpan server component

JPSpan provides a lot more functionality then SAJAX, the biggest difference you notice on the javascript side of thing is that you have mapped objects, on the php side the biggest difference is that you have a server page and a client page.

The default JPSpan server is called JPSpan_Server_PostOffice, it can be used to map entire classes to javascript, or you can pick and choose. If you were using the server on a large site you might want to add a get flag called class to limit which classes get included and registered to limit the overhead, but I haven’t had any performance problems just letting 4 or 5 integration specific classes be registered all the time.

Note: the JPSpan examples set a constant called JPSPAN_INCLUDE_COMPRESS, that strips javascript whitespace, the code that does this performs horribly, so make sure not to turn it on

<?php

// Hello World class goes here will show that next

// Including this sets up the JPSPAN constant
require_once 'JPSpan/JPSpan.php';

// Load the PostOffice server
require_once JPSPAN . 'Server/PostOffice.php';

// Create the PostOffice server
$S = & new JPSpan_Server_PostOffice();

// Register your class with it...
$S->addHandler(new HelloWorld());

// This allows the JavaScript to be seen by
// just adding ?client to the end of the
// server's URL

if (isset($_SERVER['QUERY_STRING']) &&
        strcasecmp($_SERVER['QUERY_STRING'], 'client')==0) {

    // Compress the output Javascript (e.g. strip whitespace)
    // turn this off it has performance problems
    define('JPSPAN_INCLUDE_COMPRESS',false);

    // Display the Javascript client
    $S->displayClient();

} else {

    // This is where the real serving happens...
    // Include error handler
    // PHP errors, warnings and notices serialized to JS
    require_once JPSPAN . 'ErrorHandler.php';

    // Start serving requests...
    $S->serve();

}

?>

App code

The app code is really quite simple, just like in the SAJAX case, here I just copied and pasted it into a class and put the session setup code in the constructor. You can do anything you would with a normal class here, but remember, this class is being recreated for each call from the javascript side, so if you want to keep class members between calls you’ll need to put the class instance in the session.

HTML code to display it

There is greater seperation between html and php when using jpspan, you include auto generated tieing code, this should allow for easier client side caching with a little header work, which is useful if your just using the code to add an autocomplete widget to a current site.

JPSpan can be used asynchronously (using callbacks) or synchronously (directly returning), generally you want to use things asynchronously since sync calls can cause the ui to freeze while your waiting for feedback. Sometimes this is actually what you want, but you’ll want to post some sort of please wait message if your transfering much of anything. More detail are given in a JPSpan tutorial on the projects wiki. In this example were using all async calls to match the SAJAX HelloWorld app.

If you were paying attention to the app code you might have noticed one minor difference between this JPSpan version and the SAJAX version. Addstring returns the count in this version, SAJAX automatically handles multiple async calls at once JPSpan doesn’t seem to so all that extra remote call gives JPSpan a problem.

This project is the first time i’ve used SAJAX and I think its ability to handle multiple outstanding calls is a big benifit. There is nothing to stop JPSpan from adding this ability but it has had a release lately so im guessing it will need someone to step up to the plate and write some actual code to get it done.


View Hello world app
, server.php source, index.php source

In my next post i’ll investigate how well SAJAX and JPSpan handle passing complex data types.

AJAX Hello World with Sajax

Tuesday, April 19th, 2005

So in my last AJAX post I talked about a couple AJAX toolkits for PHP. Today I’ll cover a small example using SAJAX.

Setting up SAJAX

  1. Download SAJAX: http://www.modernmethod.com/sajax/download.phtml
  2. Copy Sajax.php from sajax-0.10/php to somewhere in your include path
  3. Your good to go.

Hello World php code

Now using AJAX for hello world is a bit over kill but we need an example so in this example will display a random string generated on the php side.

App php code

Just some simple functions to add strings to a session array, return its count, and to return a random string from it.

<?php

        session_start();

        if (!isset($_SESSION['strings'])) {
                $_SESSION['strings'] = array('Hello','World','Hello World');
        }

        function addString($string) {
                $_SESSION['strings'][] = $string;
                return true;
        }

        function randomString() {
                $index = rand(0,count($_SESSION['strings'])-1);
                return $_SESSION['strings'][$index];
        }

        function stringCount() {
                return count($_SESSION['strings']);
        }

?>

SAJAX setup

Include Sajax.php and register functions that we want exported to javascript.

<?php

       require("Sajax.php");

        sajax_init();
        //$sajax_debug_mode = 1;
        sajax_export("addString");
        sajax_export("randomString");
        sajax_export("stringCount");

        sajax_handle_client_request();

?>

HTML Code

The important thing to note is that SAJAX uses callback functions for return values so for most calls you’ll need 2 javascript functions. Otherwise its just simple DOM interaction in this example.

View code of the entire script, view hello world example.

Nice boring English

Tuesday, April 19th, 2005

Everyone was filling this out on Planet Gnome, so I thought i’d see what my profile is. Just as I thought I speak nice boring general american english, though I think before I moved to Arizona I spoke a bit more Upper Midwestern.

Your Linguistic Profile:

80% General American English
15% Upper Midwestern
5% Yankee
0% Dixie
0% Midwestern

Building Rich Web Applications with AJAX

Tuesday, April 12th, 2005

So a couple months ago Jesse James Garrett gave us the worst new technology term ever, AJAX. Now I think a much better term is javascript remoting, or just javascript remote procedure calls using xmlhttpclient. But AJAX now seems to be the word of choice so were stuck with yet another meaningless acronym just like SOAP.

Now onto the actual topic, how you use the new technology with PHP and what it means to your average PHP developer. The first thing you want to do is just like another other new tech in PHP, ignore the original article and generic explanations and find a library that does the hard work for you.

Right now your options seems to be:

  1. SAJAX which offers a simple procedural api on both the javascript and php sides of the equation, It also provides support for other server side languages.
  2. JPSPAN which maps php objects to the javascript world.

Using either approach you have easy access to moving data back and forth between the php and javascript worlds, so at this point all the new tech been done for you, now you just need to use it which is the hard part. So the biggest change is you’ll be writing a whole lot more javascript, most of it interacting with the DOM. While many of use have avoided it like the plague its not all that bad if you only worry about supporting Firefox and IE 6.0, and its a pretty nice experience if you only have to support Firefox.

If you don’t enjoying playing with the DOM then the AJAX revolution will take a bit longer to get to you, but don’t worry it shouldn’t long before people start releasing widgets for doing that side as well. I expect that you’ll see type-ahead find, multi-select pulldowns, and database grids.

What this means to the average php developer is that you’ll have the abilility to reduce page reloads and make your webapp feel a lot more like a normal desktop app. At the moment you still have to do the work yourself, but im guessing you’ll see turnkey widget solutions in the next couple months. As I get time i’ll attempt to post a couple tutorials and if I ever stop spending time fixing up my apartment i’ll release the type-ahead find code we’ve built for clearhealth.

This circle expands additional navigation