File uploads with Adobe Flex and Zend AMF

Leonardo França writes; Zend AMF is an implementation done in PHP to work with the communication protocol binary AMF (Action Message Format) and is part of ZendFramework. I had to implement a system to upload files that were a little different than what is typically used in Flash, with this feature had to be integrated into the Zend AMF.
Researching a little on the net, found a solution that was simpler than I thought based on that article with a few adjustments.
Begin with our gateway to be used as endpoint in Adobe Flex.

< ?php require_once 'Zend/Amf/Server.php'; require_once 'Zend/Amf/Exception.php'; require_once 'br/com/leonardofranca/vo/FileVO.php'; require_once 'br/com/leonardofranca/UploadZendAMF.php'; $server = new Zend_Amf_Server(); $server->setProduction(false);



Read more at; File uploads with Adobe Flex and Zend AMF – Workflow: Flash.

Shine MP3 Encoder on Alchemy

Shine (formely 8hz-MP3) is a simple lightweight C-based MP3 encoder made by LAME developer Gabriel Bouvigne.

Description of Shine on his website:

The goal of this encoder was not quality, but simplicity. I tryed to simplify the encoding process as much as possible. So Shine is then a good starting point when a programmer needs a very simple MP3 encoder

This Alchemy port features:

  • MP3 encoding of mono and stereo WAVs (no time limit)
  • non-blocking encoding for progress status in flash
  • errors automatically sent to flash for easy log/debug

via flash-kikko.

Helper class to write WAV formated audio files. The class expects audio input data in a byte array with samples represented as floats.

The default compressed code is set to PCM. The class resamples and formats the audio samples according to the class properties. The resampling geared for performance and not quality, for best quality use sampling rates that divide/multiple into the desired output samplingRate.

For more information about the WAVE file format see:

via – ghostcat – AS3 library of generic tools

Flex Builder 4.5.x Test Drive for Mobile Tutorials

Here is a very good multi-part tutorial on the ins and outs of mobile client / server development, that adds some quite useful functionality on Android, Apple IOS and Blackberry mobile devices.

In this Test Drive, you are going to create a Flex mobile application that retrieves, displays, and modifies database records (see Figure 1). A Flex application does not connect directly to a remote database. Instead, you connect it to a data service written in your favorite web language (PHP, ColdFusion, Java, or any other server-side technology). You will build the front-end Flex mobile application; the database and the server-side code to manipulate database records is provided for you as a PHP class, a ColdFusion component, or Java classes.

The Mobile Test Drive application running on a mobile device.

Figure 1. The Mobile Test Drive application running on a mobile device.

via Adobe Developer Connection.

Data paging with Flex and PHP using Flash Builder 4.5.x

Flash Builder 4.5 has a built-in data paging feature that generates ActionScript code to retrieve data from the database incrementally on demand. For example, suppose your database has thousands of records and you want to fetch only 20 rows at a time and display them in a data grid. When you enable paging for an operation and bind the operation result to a DataGrid control, the first 20 records will be retrieved initially and the next page of records is fetched only when the user requests them—that is, when he or she scrolls the vertical scroll bar of the DataGrid control.

Flash Builder 4.5 lets you enable paging for any type of data service operation including operations on a Remoting service, web service, or HTTP service. This article explains how to enable data paging for a PHP-based Remoting service. After you set up the server environment required for the sample application, you’ll use Flash Builder 4.5 to generate ActionScript service classes and build a Flex application that incrementally retrieves data sets from a database table using the PHP class on the server.

via Adobe Developer Connection.

Adding Zend_Cache to Flex/Flash Builder 4 Projects

I have som rather large and time consuming queries running in the Statistics screen of an NOC (Network Operations Center) Flex/Flash Builder 4 application i’we been tinkering with, to prevent the database server to be boggen down by multiple queries fired by this app in multiple places I had to implement caching.

And to do this is alot easier than it might sound like especially for the (PHP) Zend_AMF based services.

Once you have setup your Data Centric client/server  connection like it’s described in this Article @ DevZone you begin by editing the gateway.php;

// Store configuration in the registry
Zend_Registry::set("amf-config", $amf);

// Configure Zend_Cache
$frontendOptions = array(
'lifetime' => 12*3600,
'automatic_serialization' => true,
'default_options' => array(
'cache_with_get_variables' => true,
'cache_with_post_variables' => true,
'cache_with_session_variables' => true,
'cache_with_files_variables' => true,
'cache_with_cookie_variables' => true,
'make_id_with_get_variables' => true,
'make_id_with_post_variables' => true,
'make_id_with_session_variables' => true,
'make_id_with_files_variables' => true,
'make_id_with_cookie_variables' => true
$backendOptions = array(
'cache_dir' => '/tmp/'

$cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);

// Store cache configuration in the registry
Zend_Registry::set("cache", $cache);

Then modify your service class to look similar to this;

public function getCustomerStatsByMonth() {
// Get the Cache from Registry
$cache = Zend_Registry::get("cache");
$id = 'getCustomerStatsByMonth';
if(!($rows = $cache->load($id)))
// We didnt find anything in the cache so lets get it from DB
$stmt = mysqli_prepare($this->connection, "SELECT,
SUBSTR(FROM_UNIXTIME(`cdrs`.`start`),1,7) AS `month`,
ROUND(SUM(`cdrs`.`talktime`)/60) AS `minutes`,
COUNT(`cdrs`.`start`) AS `calls`
INNER JOIN es.cdrs
ON ( = cdrs.outgroup)
INNER JOIN es.customers
ON ( = cdrs.scustomer)
WHERE (outgroups.name_invoices LIKE 'Sweden%' AND cdrs.start > UNIX_TIMESTAMP('2010-01-01 00:00:00') AND cdrs.status = 'answer' AND cdrs.talktime > 0 AND custome\
rs.parent IN (7,42))
GROUP BY,SUBSTR(FROM_UNIXTIME(`cdrs`.`start`),1,7),outgroups.name_invoices
ORDER BY SUBSTR(FROM_UNIXTIME(`cdrs`.`start`),1,7),outgroups.name_invoices;");


$rows = array();

mysqli_stmt_bind_result($stmt, $row->name, $row->month, $row->name_invoices, $row->minutes, $row->calls);

while (mysqli_stmt_fetch($stmt)) {
$row->month = new DateTime($row->month.'-01 00:00:00');
$rows[] = $row;
$row = new stdClass();
mysqli_stmt_bind_result($stmt, $row->name, $row->month, $row->name_invoices, $row->minutes, $row->calls);

// Save collected rows into the cache
return $rows;

Your queries will now be cached after the first time you run them for the specified amount of time (TTL), and boom you’re done. If you require the update function in your service classes to purge the cache simply insert;

// To remove or invalidate in particular cache id, you can use the remove() method :

Read more about cache cleaning in the Zend Cache reference.

Hope this little article helps and please comment if you guys have better suggestions.
(Yes I know I can use APC & Memcached, but in this example I didnt have to 🙂 )

Danny Froberg

Connecting Flex 4 and RESTful Web Services using Zend Framework

David Flatley writes;

With Adobe’s latest incarnation of the Flex Framework and the Flash Builder integrated development environment (IDE), creating truly engaging front-end clients is now more streamlined. Some of the useful tools and features covered in this article are the Data/Services, Test Operation, and Network Monitor additions to Flash Builder. In this article, I explain how to set up a simple Representational State Transfer (REST) service using the Zend Framework 1.9 locally and connect to it in the Flex 4 application.

To get the most from this article, you should have a basic knowledge of the Zend Framework version 1.9. Development experience locally on your machine with Apache Server distributions like XAMPP, WAMP, or MAMP is helpful but not mandatory. You will need to deploy the server-side application on Apache running PHP. There is no database connectivity for this article.

Finally, you must have Flash Builder with PHP development tools installed or some flavor of the Eclipse IDE with the Flash Builder plug-in to complete the examples in this article.

Read the Full Story.

10 X Zend Amf Performance enhancements — please test!

Wade Arnold comes with some very good news for us that use Zend_Amf, he writes; Mark Reidenbach from has submitted a awesome patch for Zend Amf that creates a huge performance increase. Thanks so much Mark! I have also added a reference check optimization that uses SPL_object_hash to quickly see if an object has been seen before or not. Overall you should see a big performance increase. The test case I used was the James Ward’s census data from my ZendCon talk which consists of random people objects ranging from 1 – 100 duplicates totaling 5k total rows.  Xdebug profiling analyzed by  KCacheGrind showed roughly a 10X increase in performance!

The question is did all of these changes introduce any bugs? I have not been able to find anything and all of the tests pass. However with such a major change I would really appreciate you downloading the attached file and overwriting Zend/Amf/* with it’s contents. Please report any issues in the comments here or better yet on the actual bug ZF-7493 If all goes well we will try and get this into the 1.10 release.

via 10X Zend Amf Performance enhancements — please test! | Wade Arnold.

ZamfBrowser 1.0

When doing AMF projects especially in AIR it’s good to see what gets returned from your Zend_AMF services, here is the solution; ZamfBrowser allows developers to unit test ZendAMF Service classes via an Adobe AIR application. Implementation requires a simple edit to the ZendAMF gateway file that allows ZamfBrowser to introspect your server set up and provide access for all classes and methods registered with the Zend_Amf_Server object. For version 1.0 the ZamfBrowser AIR source code is still closed, but it is intended to go Open Source as soon as the source code documentation is complete and a couple of features are implemented that are still in the pipeline.

Go and get it: