views:

175

answers:

2

What is the best/fast/efficient way of communicate between Flash and MySql? I have a multi-players online game using Flash-php-MySql, it seems like when I reach 5 or more players, the game is laggy. And I believe that problem is because of request and response from MySql through php. I am using URLRequest, Post method in AS3 file.

I tried google, I found this Amfphp and Zend Framework Adobe AMF. I am not sure if it helps my connection to database? Anyone tried these before? (Please include your comment about any of these in the answer)

Can you guys recommend what are the more appropriate methods of communicating between Flash - MySql in term of response time and security?

+1  A: 

Are you trying to handle frequent sever<>client data with one-way post calls? In this case you would have to constantly poll the server and open and close the connection all the time.

If you want to use PHP I'd recommend creating a socket server so that you only have one open connection all the time. You'd have to establish a connection using the Socket class in actionscript. Your PHP socket server can then retreive data from the SQL database with high speed as they are both located on the same machine and directly send this data back to the flash client using the open socket connection.

This should get you started, though I recommend using the Socket class rather then XMLSocket class as it provides more customization.

Tom
+3  A: 

ZendAMF and AMFPHP (both by the same guy, ZendAMF is newer but a little more complex to set up) are both great. Basically you have to spend the time getting both the front end and the back end set up but once you're rolling calling a PHP method is as easy as MyRemoteConnection.myMethod(myVars) in your AS3 file.

If you're working in Flex it gets even easier, you can use the RemoteConnection class and it's easy to dynamically map local AS3 value objects to remote PHP value objects.

Whether you're using ZendAMF or AMFPHP it'll be a lot faster than any sort of XML stuff because they use a binary data transfer. A good introduction to AMFPHP is Lee Brimelow's tutorial - here's part one, here's part two. Hope that helps!

EDIT: Also, I should point out that Adobe officially endorses ZendAMF for this stuff. If you're comfortable setting up the zend PHP framework on your server then go with that one, but if you want a very simple server-side setup then use AMFPHP, it's also fantastic and like I said it was built by the same guy.

Myk