php socket servers, actionscript 3 and multiplayer - php

So I am thinking about creating a multiplayer game and I was wanting to use php because I already have a php server. Is it possible to make a socket server that will be able to handle a actionscript multiplayer game. The game won't be big. so we wont need any huge amount of data pushing through. just some software that is probably reliable enough to run a multiplayer game.

PHP is clearly not a solution when it comes to socket server. It's simply not meant for that kind of usage.
If you really want to go multiplayer, SmartFox ( http://www.smartfoxserver.com/) offers a professional solution when it comes to Flash. After that developing a small socket server in a proper language is not that complicated, and the possibility are endless (Python, Java, C#, C, C++, Erlang, Go, Erlang, ...). It really depends on what kind of game you're want to do.
PHP could be eligible as a solution in case of turn by turn type game, you could simply handle it as a RESTful service (sending back and forward the game state by http).

You could use PHP, but I wouldn't recommend it. In addition you will need a shell on your server and the ability to execute custom servers, since the PHP socket server will not be running from inside the webserver (Apache etc).
I would recommend one of the many realtime communication servers available for Flash, such as Wowza, ElectroServer, Union, or others (just google for them)
There are some free ones available too, but the quality may not be as good. Some examples I found with a 30 second google serach, I know nothing about them: Oregano, GFS, Palabre

You could use Red5. It's an open source Java implementation of a Flash Media Server that allows for what you want to do:
http://osflash.org/red5

Related

Socket server on multiple ports performance

I want to build a game in AS3 and do most of the logic in PHP/MySQL since I'm more experienced in PHP than in any other language that was recommended for it like JAVA.
I've read a lot about that PHP is not a good option for a PHP socket server. The main reason was that it will not manage to handle more than about 1000 clients.
But I never found a good reply why actually it is like that? Is the PHP process crashing after it? Is it an option to set up for example 2 socket servers on different ports? Will it handle about 2000 clients then? Or still not?
If you know AS, I would actually recommend either Java or Node, actually. AS3 is very similar to both Java and JavaScript (some differences), which would make the conversion pretty painless. The magic you have to decide on is how many messages go through each of your clients per second.
If the load is light, prefer Node. If the load is heavy, prefer Java.
If, however, you want to stick to PHP, you will need multiple game instances running from CLI (NOT from Apache). You can then connect to them through standard sockets in any way you like. This is easy to do.
The hard bit is to synchronize all the instances. You can do so by having them all connect to an instance that is solely dedicated to relaying messages to the servers, or have them connect between each other. Game comms theory books and tutorials will come in handy on how to do this.
Your other issues will be, if using PHP, amongst others:
The socket connection limit per daemon
Single-threaded nature of PHP
Caching
Building an evented multi-client socket interface from something that, inherently, does not have this
PHP is at a severe disadvantage compared to Java on this. It is, however, possible.

AS3:Multiplayer Game by using AS3 with PHP?

I try to search on the Google about "Online multiplayer game" by using AS3 with PHP,because I'm going to develop Flash game that all the user can login and create his/her own character that they can walk around and Chat in the living room.
My Plan is
MySql sent User_Information to PHP then sent data to Flash (AS3) for display the information
(I try to use PHP because now I'm using PHP sever and I don't want to change it,Sorry for that)
MSQL > PHP > FLASH
I did some result from Google but I got AS3 with C#
https://playerio.com/documentation/tutorials/building-flash-multiplayer-games-tutorial/
and AS3 with JAVA
http://techylib.com/en/view/hihatclover/free_ebook_actionscript_3.0_for_multiplayer_game_and_virtual
so there are any way that I can use AS3 with PHP then MYSQL
I use AMFPHP (http://www.silexlabs.org/amfphp/) to talk to a remote server. It's free and super easy to install. Check out the documentation here (http://www.silexlabs.org/amfphp/documentation/)
There exist other MMO technologies for flash that scale much better than AMFPHP.
When building an MMO, consider how the backend will handle failure. Some level of failure from a really busy service is inevitable. The question is how many users are affected by a failure.
Scalability issues differ if the server side is a 'stateless' REST based protocol, or you are building a server that keeps state within server memory.
If you really put a load on AMFPHP, the AMF Serializer will drag the server's performance exponentially. It is simply not a linearly scalable algorithm to convert from Java to AMF serverside.
I've found that SmartFox Server (http://www.smartfoxserver.com/) is a good alternative (written in java) for multiplayer games. Its also extensible, using java. It works using Sockets, and the AMF serialization is done Client Side with the provided SmartFox ActionScript Library.
From a "quality of service" perspective, it would be intelligent to run multiple SmartFox processes on the server (running on different ports) and have each process only manage a few users. This way if a SmartFox process dies, the whole server ins't affected, only the few users being managed by that process.
A safe limit is < 15 users per process. In theory if your goal is to support 10000 simultaneous users on a server, you would have 667 SmartFox processes running on 667 different ports.
Of course this depends on the server side setup/logic, but in the simplest case, real-time MMO data from a client is simply replicated by SmartFox and broadcast to all the players connected to that process instance.
Remember, if you require further server logic, you can extend the SmartFox server with Java. But remember, the more you extend the Server, the more work is being done, and the less connections you can ultimately support (per server).
You can program Actionscript 3 in Flash Builder and it provides more advanced tools to consume PHP services, also Flash Builder is capable of generate the basic CRUD to consume these services using the Zend Framework, here is a basic tutorial for PHP programmers : http://corlan.org/flex-related/flex-for-php-developers/
also take a look here
http://www.adobe.com/es/products/flash-builder-php.html
I am working on a similar kind of game and I am using php to communicate with mysql as well.
The tutorial I am using is:
http://active.tutsplus.com/tutorials/actionscript/create-a-flash-login-system-using-php-and-mysql-part-1/
As for the playerio, I am also a bit confused.
There is a couple of multi player gaming servers are available.. my favorite one is SmartFoxServer 2x http://smartfoxserver.com/
however, you can develop a multiplayer game by using php and Flash as3 for that you have to create a PHP socket server program to handle Actionscript request. This can be achieved after you done creating PHP socket Server and you have to create socket connection from flash and connect to php socket server.
Kindly see this link for creating socket program in php :http://www.christophh.net/2012/07/24/php-socket-programming/
kindly refer this link for creating actionscript socket programming
http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7cfb.html

How to integrate a scalable long-polling server with PHP?

I've been "recruited" so to speak to help work on a web project that is currently written in PHP with an Apache server. We would like to integrate a real-time (or at least something very close to it) chat feature. Scalability is a definite concern, and this type of work is definitely not my typical.
Everything I've read about creating such a chat feature requires the use of "long-polling" so the servers don't get rapidly overloaded and, well, crash. PHP and Apache are not conducive to implementing such a feature, so I've explored some alternatives, like Twisted Python for example.
The website has roughly ~7,000 lines of PHP (i.e., it'd pretty difficult to just straight switch languages for the entire thing), so my question is how can I manage this situation as far as trying to integrate python and setting up a separate server? Or, is this a very bad way to do this? Are there other alternatives that would be better suited? (Sadly many of the PHP Comet, or even AJAX, solutions I've found don't scale in the slightest. Note, the Apache server is not necessarily required; however, any server used must work with PHP and Python etc, short of having separate servers.)
Thanks for the help!
I would use Tornado on the server to write the chat application. Client server communication can then be over websockets. If you use SockJS on the client side you can also support older browsers via long polling. There are plenty of example chat clients written using Tornado. It's very simple to get started and it is wonderfully scalable. A chat server like this can be serving thousands of clients without showing any appreciable CPU activity.
This is an example, possibly a bit over engineered https://github.com/diggidanne/websocket-chat/blob/master/server.py

PHP & COMET. Need some guidance

I have been in search of making live websites by using PHP. (COMET) I have been searching for a very long time already. (around a month) I have even checked some PHP chat scripts and used on my webserver, but I had some problems on most of them. (will be explained)
So far, most of the people tells the same thing: PHP isn't the best language could be used with COMET. The chat/comet examples are hacky at best.
I am asking this because, I want to have some features on my websites, like allow logged in people to chat with each other. That is where I need an alive connection to PHP pages. I am also planning on making a browser based game, and an alive connection will still be a must!
AJAX was a rare thing 2 years ago, shined with Facebook. Now pretty much everyone uses it, and it became a standard on web development. Now, the COMET based websites are growing. Youtube, Google+, Facebook, EA's Battlelog and such. I believe I should learn how to use it.
Okay, here are my questions. (Some of the information at below are the ones I gathered while searching on Google. Not sure if they're correct or not.)
Some languages like Python have special web servers designed for this job. I believe one of them is called Tornado Web Server. Developed and configured to simulate thousands of alive connections. I believe there is no such option in Appserv, but some people told NGINX can handle it with a decent configuration. Is it true? What configurations should be made? Is there any PHP web servers for this job?
Some of the most suggested things are:
a. Using APE.
b. Using Socket.IO
c. Node.js
Is there any way we can use them with PHP? Which one is the most promising? Could you give some guidance on them? Is there anything else than these?
I have used a comet chat script. Basically, you kept querying database and output the result with flush() to browser by sleeping it with usleep() in a loop. (This one became hard to understand so I will provide a quick code)
while(true)
{
// query database
// output the result
// flush the browser
// sleep for few seconds to lower cpu load
}
usleep() function basically destroyed my web server on Windows based operating systems. Is it normal to rely on usleep() on comet applications which runs on windows based OS? I mean, is there even a way to "sleep" PHP scripts? No matter what I do, CPU load goes to %100 on both WIN and UNIX servers.
Is PHP "really" that weak on this area? Should I give up with PHP and focus on other languages? If so, which language would you suggest? (That language should be promising. For example, there is no much use of AS3 after HTML5 addition, and AS3 is more likely to die soon while JS shines.)
What is WebSync? Can it be used with PHP?
Please bear in mind that I need to use COMET to make following applications:
A chat script, where logged in players will be able to chat eachother.
A browser based game. I already use JSON/AJAX and things like that when coding, but to receive opponents steps, I should pull the data, so an alive connection is needed. (Don't imagine advanced games, I am speaking about games like chess at best.)
I would appreciate if you can give me a short guidance. After all, I have been getting confused day by day since there are SO MANY random articles on internet. People even call setInterval() as COMET, so it is a complete mess.
There needs to be some clarification here. What you're looking for is not language specific per se. If you wanted to achieve the comet functionality with PHP you'd be relying on the Web Server (e.g Apache) to do the HTTP streaming. Also you need to understand that this is not supported in HTTP versions prior to HTTP/1.1. With that said, if you want to have a non-blocking event based web server, you're better off looking at Tornado and Node as suggested.
Comet is a programming technique that enables web servers to send data to the client without having any need for the client to request it This technique will produce more responsive applications than classic AJAX The user must create a request (for example by clicking on a link) or a periodic AJAX request must happen in order to get new data fro the server.
but it's create lots of traffic on your web server. If you want to build chat application in PHP use pusher which is a third party service and easy to use.
here is a link for pusher https://pusher.com/tutorials/realtime_chat_widget
the second suggestion is use ratchet for creating a chat application.
here is link for ratchet http://socketo.me/docs/hello-world
i hope it will help you

What technology can be used for this browserbased ping-pong game?

I just saw the McDonald's commercial which I have linked to below and I would like to try developing something similar for a festival. We have been talking about making a game in which the user has to use their iPhone and something like what McDonald's has done would be great.
My question is if anyone have an idea how I can send the data and what technology they might have used? I imagine making two websites. One on which the game itself is shown and one which is the controller but how would I make sure that the data is sent and handled fast enough?
I am familiar with JavaScript and PHP. I have been working a bit with flash and ActionScript and I am wondering if that might be best for the game (obviously not the controller)
You can see the McDonald's commercial on the link below. Basically, the user visits a webpage which is the controller and then they are able to play the ping-pong game on the big screen.
Any ideas and brainstorming on how to do this is welcome.
Watch the McDonald's Pick n Play commercial here.
Just use WebSockets. The problem with them is browser support and supporting older browsers / platforms.
To handle this there are various abstractions. I would personally recommend socket.io A solid abstraction that relies on node.js. Has a range of fallbacks (including COMET and Flash). Whilst your at it, you might want to looking into using node for realtime applications (it's great!)
I would create a socket server that hosts the game (socket TCP/IP connection). The purpose of the socket server application would be to listen for connections, wait for 2 players, start the game, decide who wins and sett-era (it could also have some queue of players that will play next and inform the players where they are in the queue).
Now, how do we establish a connection from the website to that socket server?
I wouldn't use WebSockets because it's not widely supported at the moment, disabled by default in FireFox and IE does not have it implemented yet (AFAIK).
Now you have to decide, do you want to do the website in Flash or HTML. You could even use hybrid of both. For example:
Hybrid:
Use the Flash application on the controller website to act as the communicator between JavaScript and the server. When Flash retrieves data from the socket server then it will make JavaScript take care of the retrieved command. E.g. move pad up. (I use that method for my online chat application and it works like a charm).
Flash only:
Use pure Flash application as the controller and communicator to the socket server.
Voila! You have something similar to the MacDonalds game.
I hope my answer is clear enough and feel free to comment if some of my statements are wrong.
In my view, This is what I would go for :
A small client app that will be downloaded when connected to the website.Considering it in mobile platform, java app preferably. Alternative is flash, which is also suitable, but if graphics is not our aim then I suppose better hold it off.
A server to provide real time connections to the users one-at-a-time. (As shown in video). This is the actual pain for all the games out there. I would go looking for one of these projects as platforms:
http://opensource.adobe.com/wiki/display/blazeds/BlazeDS
http://www.smartfoxserver.com/
http://www.cubeia.org/
http://appengine.google.com/
Besides that, ideas - I would have liked if it was multi player (there was quite a crowd), but that would have meant at least person winning every game & more of free give aways for them.
As alternative can be COMET a web application model in which a long-held HTTP request allows a web server to push data to a browser, without the browser explicitly requesting it
have a look here: Comet

Categories