2

I'm using Flex 4. Have PHP backend and mysql database with one table consisting of multiple rows.

I take the raw data from the result event and decode it using JSON. I then dump the data into an ArrayCollection that I use as my datagrid's data provider.

My question is how can I tell when someone inserts a new row into the mysql table so that I can automatically refresh my ArrayCollection, thus seamlessly updating my datagrid one element at a time? Right now, it's just a one time call and the connection is closed. If someone inserts a new row into the database my program doesn't recognize, unless I restart it. I'd like to auto-update the AC whenever a single new row is inserted into the mysql database. Is there a way I can "listen" for this change?

Cœur
  • 32,421
  • 21
  • 173
  • 232
Mike P.
  • 21
  • 1
  • Hi Mike, The thing you are trying to do is called comet,or server push.As of now, very few servers support this.Refer to this request to know how to use comet with Apache.http://stackoverflow.com/questions/603201/using-comet-with-php.Once you are through with the setup, you will need to create a flex comet bridge.Incase you are interested to go forward with this solution, reply, I will provide you the code for flex comet bridge, as I have used it in some application , but the backend was in java. – Neeraj Apr 18 '11 at 10:27

2 Answers2

0

No, there is no automatic way to do that. But you can regularly 'ping' your server and ask for new rows. Use

setInterval(myFunctionName, timeToWaitBetweenEachCallInMilliseconds);

to do that.

Sam
  • 6,961
  • 15
  • 44
  • 63
Bil
  • 560
  • 3
  • 15
0

Ah, you've stumbled upon the age old question of the web realm: Polling or Pushing?

Polling means that you ping the server every few seconds or minutes to check if there's any data that has changed. If there is, your server sends you the new changed data which up update appropriately on your front-end. The 'protocol' on how to interpret which piece of data needs to be updated is totally up to you since there's no real standard (since data in itself can be very different from system to system). Polling is still in use today in many systems that do not need crucial 'live' information and since it doesn't need a consistent connection, it's particularly good for iffy internet like mobile. Plus, everything is an HTTP request, so there's no enterprise firewall that can block it.

Pushing means that you have a constant connection between your front end and back end which normally goes over RTMPT (HTTP UDP protocol to circumvent enterprise firewalls, but not 100%). It's great if you need real time data (like say financial data) to be delivered to you quickly. However, the user needs a consistent internet connection and you need to have a server capable of dealing with the amount of connections and sessions management. Normally, most people end up using Java since there are many libraries to handle pushing (BlazeDS, GRaniteDS, Livecycle, Wowza, etc).

Since you're using PHP, you'll probably need to use polling as your solution, but need to implement it yourself. I'm sure there are libraries out there to help you out though.

J_A_X
  • 12,824
  • 1
  • 23
  • 31