An efficient way to communicate between Flash and MySql?

What's the best / fastest / most efficient way to communicate between Flash and MySql? I have a multiplayer online game using Flash-php-MySql, it looks like when I reach 5 or more players the game is laggy. And I believe the problem is with the request and response from MySql via php. I am using URLRequest, Post method in AS3 file.

I tried google, I found this Amfphp and Zend Framework Adobe AMF. I'm not sure if connecting to the database helps me? Has anyone tried them before? (Please add your comment to any of these in the answer)

Can you guys recommend the most appropriate ways to exchange information between Flash-MySql in terms of response time and security?

+2


source to share


2 answers


ZendAMF and AMFPHP (both the same guy, ZendAMF is newer, but a little tricky to set up) are both great. Basically you need to spend time setting up the front and back end, but once you move on to calling the PHP method, it's as easy as MyRemoteConnection.myMethod (myVars) in your AS3 file.

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



If you are using ZendAMF or AMFPHP it will be much faster than any XML stuff because they use binary data transfer. A good introduction to AMFPHP is Lee Brimelow's textbook - here is part one , here is part two . Hope it helps!

EDIT: Also, I should point out that Adobe officially supports ZendAMF for this. If you are more comfortable setting up the zend PHP framework on your server then go for it, but if you want a very simple server side setup use AMFPHP, it is also fantastic and as I said it was built by the same guy.

+3


source


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

If you want to use PHP, I would recommend creating a socket server so that you only open one open connection at a time. You will need to establish a connection using the Socket class in ActionScript. Your PHP socket server can then fetch the data from the SQL database at high speed as they are both located on the same machine and send that data back to the flash client directly using an open socket connection.



This should get you started , although I recommend using the Socket class over the XMLSocket class as it provides a lot of customization.

+1


source







All Articles