Archive for the 'PHP' Category

PHP AJAX File Upload Progress Meter Updates

Tuesday, March 14th, 2006

Over the weekend my file upload progress meter code got lots of traffic. It seems it made it made it on the del.icio.us popular list as well as getting over a thousands diggs. To celebrate this i’ve updated the code.

The main new feature is giving you feedback without having to patch PHP. Now the patched version gives you more information such as upload speed and estimated time to completion. But we still provide some nice user feedback even without it now.

I also created some wiki pages to start the documentation process.

So here are the demo’s

With the patch and extension
Without the patch

To get upload speed you will need to download and install the PHP Upload Progress Patch and extension.

If you want to use the code you need to:
Install HTML_AJAX (pear install HTML_AJAX-alpha)
Download PAFUPMU and install it somewhere accessible.
Add the code to your page using demo.php as an example.

The basic way the code works is we take a form containing a file upload and submit it using a hidden iframe as a target. Doing this lets the upload happen in the background. Then we poll the server on a regular basis (say a 2 second interval) asking it for update status. If you have the patch+extension installed this gives you file upload speed etc. If you don’t have the extesion we stop making AJAX calls and just animate the status bar until the upload finishes in the iframe and tells us were done.

In demo.php we handle generating the current page and handling the upload in the same page. So we start by handling the update.

<?php

include 'UploadProgressMeter.class.php';

$fileWidget = new UploadProgressMeter();

if ($fileWidget->uploadComplete()) {
        // output javascript to the iframe to send a final status to the main window
        // this will catch error conditions
        echo $fileWidget->finalStatus();

        // move the file(s) where they need to go

        exit;
}
?>

?>

This code only runs when your uploading so you’ll never see the output of it. This can make debugging problematic. One way around this is too hack the UploadProgressMeter to make the iframe non hidden.

Next you setup the JavaScript needed, first HTML_AJAX and then the uploaders JS.

demoserver.php is included in the source, you might want to name it something else if you actually use this code. Its just a page using HTML_AJAX_Server to register the UploadProgressMeterStatus class

You also need some CSS to style the progress bar. The only important thing is that .progressBar and .progressBar .bar are relatively positioned.

Finally you finish things up by building a form. Note that you can include other elements in the form, but if they need to produce output you’ll have to manage calling back into the parent page from the iframes output.

Zend Framework License

Sunday, March 5th, 2006

Does anyone know if the Zend Framework License is GPL/LGPL compatible.

I’m guessing that clause 5 kills compatibility but maybe that can be read as redistribution must include the license file which seems reasonable.

Why can’t people just use the 3-clause BSD license or the lgpl for code like this instead of making things more complicated.

Update:
The possible problem with using Zend Framework code in an GPL application is clause 6 of the GPL:
Within Clause 6 of the GPL is the statement: “You may not impose any further restrictions on the recipients’ exercise of the rights granted herein.”

I’m also think that clause 3 also makes it incompatible and is something that can be covered through trademarks and doesn’t even seem to fit into what a normal OSS license does.

For example the FSF says the almost identical PHP license is incompatible with the GPL.

For all the talk about making things legally easier for users they sure didn’t pick a license that does it. The best option for minimal effort by users of frameworks or libraries written in PHP is the 3-clause BSD. Its simple, well understood, and easy to find information about. Plus its compatible with pretty much every other OSS license.

PHP4Mono

Saturday, February 25th, 2006

I found an interesting project reading planet gnome today. It seems someone has written a PHP compiler for mono. Its hard to tell how far along the project is, since the focus seems on doing mono-ish things in PHP rather then running PHP apps on mono. But the project is open source (GPL) and it does let you use PHP within the wider mono world so thats pretty cool.

Of course that brings up the question, does anyone really want to use PHP inside a managed runtime like mono. I can see the advantage of using PHP to make a GUI app using mono’s gnome stuff since it would be less to learn (if thats actually true) but what would I gain running my web apps using mono, besides less compatability.

Also I know there is the Phalanger project but its not open source so im not interested in looking at it at all.

Cleaning up bugs

Friday, February 24th, 2006

I woke up this morning with 52 emails from Sourceforge. Nothing like being huge loads of bug spam because Greg is working on cleaning up phpDocumentor bugs.

Anyhow I just wanted to thank Greg, and make a couple notes about what good bugs contain.

phpDocumentor Bug submission guide:

  • phpDocumentor Version
  • PHP Version
  • OS Version
  • How your running phpDocumentor, CLI, CLI+ini file, Web interface
  • Instructions on howto reproduce the error
    • A simplified set of code to parse that produces the error
    • How you have phpDocumentor configured, an ini file being the prefered way rather then a mile of command line parameters

Oh patches for bugs are more then welcome, just make note that phpDocumentor 1.3.x development is taking place in PEAR cvs so make it against that.

AJAX and Latency

Monday, February 13th, 2006

So i just saw a great piece by Harry Fuecks on how latency can effect AJAX requests. Its one of his demo’s from the ajax@localhost presentation he gave at the PHP Conference Uk.

Now this showed a number of interesting problems, and while HTML_AJAX does a bit better then some toolkits it doesn’t handle them all. However thanks to HTML_AJAX’s design it not that hard to work around some of them.

So to that extent here is a really simple livesearch demo that keeps the reponses in the same order as the requests. The server is adding latency for you so you don’t need to worry about setting up a proxy to try it out. This is only available from HTML_AJAX svn right now, but we should do a release in another week or so there are lots of other good fixes in it.

Please note this queue isn’t really all that great for livesearch (ie it pounds your server). The current queue that is recommened for livesearch (and the one that HTML_Quickform_Livesearch (demo on my server, not the final version) uses sends a request at a maximum rate of every 350ms (this rate is configurable) instead of per character typed.

Finally this is just a quick hack, if you set the latency up too about 10 seconds you’ll start hitting some bug in the timeout code. The timeout is getting combined amoung multiple elements or something. The JS code might be really leak happy too, the queue doesn’t actually have all that much control of what happens when a request is complete just in when it sent in the current design. So to get around this i replace the users callback with one in the queue, and then do some closure fun. And here is the new queue code if you want to take a look.

HTML FAQ Answer: Other library integration plans

Tuesday, February 7th, 2006

I answered an FAQ question tonight on the HTML_AJAX wiki, im posting the answer here as well since I know most people don’t check the wiki for changes every day.

Outside of this answer I’d like to hear from what other libraries people would like too see integrated with HTML_AJAX and the reasons for this.

Question:
Will HTML_AJAX integrate with other Javascript AJAX libraries such as scriptaculous? How would this integration look like?

HTML_AJAX doesn’t have specific plans to integrate with other JavaScript libraries. Part of this is because external dependencies make for a more complicated installation process. It might make sense to offer some optional dependencies on a library like scriptaculous automatically using its visual effects for the loading box or something, but there isn’t a lot to gain from making default visuals like that flashier since they are designed to be easily replaceable.

Most integration would take place in higher level components. Its unclear weather higher level components like that should be part of HTML_AJAX delivered through PEAR or if they should just be supported by HTML_AJAX and made available from http://htmlajax.org or some other site. If your interested in building widgets or components based on HTML_AJAX please let me know.

HTML_AJAX does however offer the ability to use its library loading mechanism with any JavaScript library. I use scriptaculous in conjunction with HTML_AJAX and I load both libraries through the server.

To do this you just need to register the library with your server and load add its flag to your include line.

PHP code

<?php

$this->server->registerJSLibrary('scriptaculous',
    array('prototype.js','scriptaculous.js','builder.js','effects.js','dragdrop.js','controls.js','slider.js'),'/pathto/scriptaculous/');

?>

HTML

PHPMagazine.net Interview

Thursday, February 2nd, 2006

I did an email interview with PHP Magazine.

Its mainly about HTML_AJAX but there were also some general AJAX questions and questions about PEAR. Responding to an interview like that takes a lot longer then I thought. Anyhow if your interested in the future plans of HTML_AJAX check it out.

HTML_AJAX 0.3.4 is released

Tuesday, January 31st, 2006

HTML_AJAX 0.3.4 was released today, it contains lots of bug fixes so if you use HTML_AJAX you’ll want to upgrade.

Release notes and testing results are available on the wiki, and the examples are available online if you want to see some of the basic features.

I’m hoping to do a beta release soon, so if you have time to help with an API review please get a hold of me.

HTML_AJAX Feature of the Week: Javascript Behaviors

Tuesday, January 24th, 2006

I’m trying out something new here, every week i’m going to write a short post describing an HTML_AJAX feature. Hopefully this will get some people started using the new features and maybe even get some more developers helping out with the project. It will also give me a place to try out some material for my upcoming AJAX book.

JavaScript Behaviors

JavaScript Behaviors are pieces of JavaScript code applied to DOM elements through the use of CSS selectors.

HTML_AJAX ships with a slightly modified version of the Behaviour javascript library. The slight modification is the replacement of the css parsing/selecting code with Dean Edwards cssQuery() library. This was done for a couple reasons, first the css code in behavior is under an unknown license and Dean’s code supports more of the css selector including most of css3.

I also used the American spelling of Behavior instead of the British (darn extra u’s)

Turning Behaviors on

Assuming you already have HTML_AJAX installed all you need to use behaviors is add “behavior” to your list of libraries.

If you just wanted the behavior library you could do:

Or including it with some of the other HTML_AJAX pieces

Adding Behavior Rules

In most cases you’ll want to put your behaviors in their own JavaScript file, that way they can be reused and they don’t clutter up the html, thats the point of them after all. But you can just toss them in a script block in any file.

An example rule is shown below:

Now this rule is rather worthless since its just setting a style rule, something that css is much better suited for but it does show a couple important things. You have immediate access to the matching elements, this allows you to create new child elements, update properties including innerHTML, and set event handlers.

You can set event handlers using onEvent methods but i prefer to use a couple util methods in HTML_AJAX that map to setEvent etc.

A more useful example which submits all the forms on a page using AJAX is shown below:

There isn’t a lot too see here, we build a function to handle the submit event. It submits the form using HTML_AJAX.formSubmit, the first param is the form to submit, the second is the element to update (The second element is optional but do a bug in 0.3.3 it not being set isn’t detected correctly so you’ll have to upgrade to 0.3.4 to skip it). Then we cancel the normal form submission.

Wrapping it up

These examples show some of the power of behaviors, but there really is a lot more that you can do with it. If you have any tips feel free to leave them on the wiki or as comments to this post.

Run the example.

View the full example Source.

Download the example code.

azPHP January Meeting Tonight

Tuesday, January 24th, 2006

After a long holiday break azPHP is back, our January meeting is tonight and we have a couple great presentations lined up.

The meeting is tonight 7:00pm at Walt’s TV in Tempe be sure to invite anyone you know that might be interested.

The meeting will have two two presentations each around 45 minutes long and then will finish things up with a open QA Session answering questions about the presentations or about anything else that is PHP releated.

The Presentations are:

Beginning Presentation: An introduction to the JavaScript DOM and scriptaculous by Jon Roig
Advanced Presentation: Generic Data Objects by Brian Ross

Meeting Timeline –
Tuesday Jan 24
7:00 - PHP News
7:15 - An introduction to the JavaScript DOM and scriptaculous by Jon Roig
8:00 - Generic Data Objects by Brian Ross
8:45 - QA Session
9:30ish - Social Hour(s) at Old Chicago

Uversa is Hiring

Friday, January 13th, 2006

My employer is looking to hire a couple PHP developers.

At Uversa were lucky enough to release many of our products under the GPL, you can see some of our Open Source work at our OP/EN site.

Were are also doing quite a bit of AJAX these days so this could be your opportunity to do some fun JavaScript programming as well.

Also don’t worry to much if your not in the Phoenix area, as long as you can work on the same timezone there shouldn’t be too many issues.

Feel free to contact me if you have any questions about Uversa or the job openings.

ZActiveRecord can’t work?

Monday, January 9th, 2006

In the webcast the following active record example was shown. This looks nice and slick but I don’t see how its possible, at least in php 5.1. There is no way to get the class name of the child in in the find all method.

<?php

< ?php 

class Person extends ZActiveRecord {}     

$people = Person::findAll(array('nameFirst' => 'Daniel')); 

foreach ($people as $person)
{
    echo $person->nameFirst . "n";
} 

?>

?>

This example shows how get_class doesn’t help it always returns parentstatic

<?php

< ?php
class parentstatic {
    static function findAll()
    {
        echo get_class();
    }
}
class childstatic extends parentstatic {
}
echo parentstatic::findAll();
echo childstatic::findAll();
?>

?>

Anyone have a clue on how Zend is planning to get around this problem. From what I can tell its impossible and I haven’t seen anything on 5.1.2dev that would solve the problem but I could just be missing something and there is an easy way around the problem. To me it looks like PHP forces you to do a none static activerecord implmentation.

Update:
This also came up in the comments of Chris’s post about the webcast.

Update after comments from Mike Naberezny:
Webcast showed what Zend hopes will be the final syntax, they are working on a PHP engine level solution, but since they want to work with current php5 installs we will see some other solution as well. Of course the code with work with non-static usage, though thats not as nice Semantically.

PHP Conference in London

Monday, January 9th, 2006

The PHP London user group is staging the UK’s first dedicated PHP conference on Friday February, 10th 2006. It looks too be a well planned conference with lots of great speakers. The talk by Harry Fuecks about AJAX and what he has learned creating his JPSpan project looks really interesting. So does the security talk by Christopher Kunz.

Last year while I was living in London I got to take part in a number of PHP London meetings and it was great fun. Im sure this conference will be a lot of fun as well given all the great people involved. Its really nice to community driven conferences take place, hopefully a successful conference in London will prod other user groups into action as well.

I won’t be able to make it too the conference since I don’t have time for that much traveling but if you’re in the UK (most of Europe too for that matter) it should be a great event.

Wordpress 2.0 Upgrade

Friday, December 30th, 2005

Wordpress 2.0 has been released, its got lots of new features, but as far as I can tell they are all on the author side, not the reader. A full list of the changes is available over on the asymptomatic blog. There is a bit of AJAX in the interface as well, they could use it remove a couple more dialog popups, but editing is much cleaner now. If your running wordpress and are looking to upgrade there is a good article in the support forums walking you through the process.

The release process seems a bit odd though, the files exist, the website is updated, but there isn’t even an blog post announcing the release.
I’m also using the new akismet anti-spam plugin, I hope its good since they force you to create a blog at wordpress.com to use it.

Update:

Offical wordpress 2.0 release announcement is out, has the complete feature summary.

Looking for HTML_AJAX Success Stories

Thursday, December 8th, 2005

If you’ve used HTML_AJAX to make something cool I’d like to hear from you.

If what you’ve created is publically accessible that would be even better.

Just leave a comment on this post saying what you’ve created and given a link to it if you can. Any suggestions on improvements that would make further development easier are also appreciated.

HTML_AJAX 0.3.1 Released

Monday, December 5th, 2005

HTML_AJAX 0.3.1 is out, lots of good bug fixes, and iframe fallback support for Opera and IE with activeX turned off.

More details are available on the release notes on the wiki.

I would like to thank Elizabeth Smith for all her testing and bug fixing in this release.

Feature wise were getting close to beta release, its mainly getting a browser compatability test suite added in and doing some basic API review. If you have experience supporting an API without breaking bc, it would be great to get your feedback on HTML_AJAX.

HTML_AJAX 0.3.0 Released and new Website

Thursday, November 17th, 2005

HTML_AJAX 0.3.0 is huge leap forward from the previous versions, although it still remains mostly backward compatible with earlier releases. Currently the only change in API occurs in Main.js - some event handlers were colliding so name changes were made. The effected methods are onOpen -> Open, onLoad -> Load, onProgress -> Progress, onSend -> Send. This shouldn’t affect too much code.

One of the most important and exciting changes with HTML_AJAX 0.3.0 is the addition of three new developers who have been putting a lot of time into the project. They totally eradicated every item on the original todo list, and the feature roadmap has jumped ahead.

There are considerable improvements in the behind the scenes code. Using the new HTTP client pooling reuses XMLHttpRequest? clients, giving you a speed up when making lots of requests. This is especially useful for IE, where activex object creation can really slow things down. The new priority queue allows you to make many requests and tag the ones that are more important to be sure they are executed first. HTML_AJAX_Util received several bugfixes and new methods to make debugging javascript a little easier, including a varDump() and getType(). As the code base grows, both in javascript files and in php files, some minor rearranging has been done as well.

On the user end, there are several new serializers to use - you don’t have to be limited to just JSON, Error or NULL. Now you can use php based serialization, url encoding serialization, or HTML_AJAX_Action - which eliminates the need to write client side javascript to handle the data returned from ajax callbacks. There were several bugs fixed - most importantly was a huge bug in Opera and the way it handles unknown Content-Types - it seems to translate them to binary so a workaround was needed.

The examples directory has some great new code to show the power and flexibility that HTML_AJAX can provide in applications. There’s still a lot to do, just take a look at the roadmap, but with this release a huge amount has been accomplished.

As always were still looking for new people to help out. People willing to put time in testing and supply bug fixes for there browser of choice would be especially helpful. It doesn’t take a lot of time unless your favorite browser is horribly broken, but the through testing makes a huge quality difference.

You can upgrade your install as always using the pear installer. If your looking for a full changelog you’ll want to check out our new wiki.

The couple pages of docs I’ve had here on my blog are moving there. Were using yawiki from Paul M Jones, and aside from a couple minor points its been great to work with.

HTML_AJAX 0.2.5 released

Tuesday, November 1st, 2005

This is a minor bug fix release, the big fixes updating serverl url handling and some fixes allowing you to specify a class name with case when exporting it.

The server url handling allows you to add parameters like a session id to your url.

The case changes allow you to register a class like:

$server->registerClass($instance,’NameWithCase’);

and have it work right on php4 and php5.

The second change was made while updating the UploadProgressMeter to php5. I don’t have a tarball release of that yet, but its in svn (web) now if you want a version that doesn’t rely on JPSpan.

Introduction to HTML_AJAX slides available

Wednesday, October 26th, 2005

I gave a presentation at yesterdays azPHP Meeting.

The slides from this are now available.

Also there should be another HTML_AJAX release today fixing and annoying bug.

HTML_AJAX 0.2.3 Released

Monday, October 24th, 2005

This release is a mix of bug fixes and new features.

There shouldn’t be any reference bugs left so those of you running on php 4.4 or 5.1 should be fine now.

The only item that should cause you problems is that php 4 exports method and class names to JavaScript lowercase while php5 does it in the specified case. So if you want php4 and 5 compatability you’ll need to specify the methods to export. A lowercase all option is on the list of things to do.

Changes:
There is now a append util function on HTML_AJAX
New HTML_AJAX_Debug and HTML_AJAX_Helper classes, look at the examples to see there basic use
HTML_AJAX_Server::registerJSLibrary added to allow you to use the same server class to export you own js libs
multiple client libs can be combined into a single request server.php?client=main,httpclient,customlibname (see helper_usage.php in examples for details)

The default loading implementation has been moved to its own javascript file. If you don’t want the default implementation just don’t include this lib. The implementation has also had a half second timer added so it only shows on slower calls, so if your using it on intranets, you won’t see if for your really fast calls.

Start on a serializer built on php’s serialize call. Be aware this hasn’t had much testing and that it has security issues in older versions of php (bug in unserialize call) and may never work correctly with multibyte characters until php6, but it may be faster and like any serializer its optional.

I’m sure there was some other stuff too. Also like any OpenSource project were looking for more help, including people willing to work on docs, do core development, and auxilary classes for items like template or framework integration. Some widgets may also find there way into HTML_AJAX as optional components so if your interested in writing any let me know.

This circle expands additional navigation
You should really buy my AJAX book.
You'll learn not only the technology you need for implementation but also an understanding that will help you get the most from AJAX.
You'll also have my eternal thanks :-)