3

I am working on a project that uses PHP to create an 'complex' object with lots of references to other objects linking back to their parent objects etc...

The object structure is then serialized by the Zend AMF module and sent over to the flex application.

The problem is that serialization takes a lot of time (+10sec).

My question is thus: can anybody give me tips on how the serialization works and in what way I may be able to optimize the object structure in order to make serialization run faster?

Lance Roberts
  • 22,383
  • 32
  • 112
  • 130
Goldfrapper
  • 100
  • 5
  • use APC or MEMCACHE ! it should help – tawfekov Nov 29 '10 at 14:05
  • As far as I can tell it is impossible to cache the binary AMF response since it responds to a complex POST request, caching the PHP generated object structure is senseless since it runs in no time. – Goldfrapper Nov 29 '10 at 14:33

3 Answers3

1

Switching to JSON will help a great deal with this, as it allows easier caching.

APC will also help, just for the opcode-cache part, not for storing objects in memory.

How big is this object exactly? Could it be worth it not sending the entire thing? If you're just dealing with recordsets, you might be able to fix it in the frontend by only downloading only what the user can see, or will see in the near future.

Evert
  • 93,428
  • 18
  • 118
  • 189
  • A have no access to the flex/flash app. The data model is fixed by the flash dev. And he wants all data at once. – Goldfrapper Nov 30 '10 at 13:20
0

The default serializer will iterate through every property, if a property is an object it will then iterate through each of those objects and their properties until it's done.

Since your object is complex, there's lots of crunching going on and many levels of objects that are being serialized.

As a point of optimization you may wish to look into implementing the serializable interface on your objects and serializing the minimal amount of information you require to be serialized and sent over the wire to your Flex app.

http://php.net/manual/en/class.serializable.php

Darryl E. Clarke
  • 7,537
  • 3
  • 26
  • 34
  • Will Zend AMF use the serializable implementation when serializing to AMF-3? – Goldfrapper Nov 30 '10 at 13:18
  • Now that I look at the code for Zend_Amf_Parse_Amf3_Serializer, I see that the serializer is completely custom (nice one, Adobe) - so no, it won't use this serializer interface. My answer is useless in this particular case. :) – Darryl E. Clarke Nov 30 '10 at 13:36
0

When doing AMF serialization, or any serialization for that matter, it is usually better to work with smaller pieces of data if performance is a concern. By doing that you can work with individual objects as true ActionScript objects instead of just data placeholders. Smaller data when doing any type of RPC is usually better. You could use JSON instead, but then you'd loose the tight data binding that you get from using AMF. So try working with smaller packets of data using multiple HTTP requests.

Kevin Schroeder
  • 1,296
  • 11
  • 23
  • The dataset and it's model is fixed by the flash dev. So I can't make changes there. I need to know how Zend AMF serializes the data, I already use the Zend_Amf_Value_Messaging_ArrayCollection object for array containers – Goldfrapper Nov 30 '10 at 13:23
  • 1
    The serializer is done internally by Zend_Amf_Parse. There are two types of serializers; Zend_Amf_Parse_Amf0_Serializer and Zend_Amf_Parse_Amf3_Serializer. They take the return value from the service class call and turn it into a string. If you want to see what's going on try using the Zend Debugger/Profiler (http://www.zend.com/en/community/pdt) or better yet, install a trial version of Zend Server (http://www.zend.com/en/products/server/) and use Code Tracing to see exactly what is being called at runtime. – Kevin Schroeder Nov 30 '10 at 13:58