I'm working on a PHP application and I'm looking for some ideas for a real-time protocol that I can use for:
1) track users status and location within the application (this should be fast!!!)
2) chat system.
I'm looking for something like FMS and its "Shared Objects" where multiple users can subscribe to pieces of information. FMS is expensive and slow for what I need, I would need a widget loaded on each page, requesting a new connection to the FMS server, etc.... slow...
I need something fast, ope source would be perfect!. Something like what Google Waves uses for syncing shared documents.
Any suggestions?
If you are willing to write this in PHP, I'd say you are looking at the wrong technology. There is 2 major problem with PHP and real-time.
When you run a PHP application, it is not persistant like Servlet with Java. It is hard and not really adapted to do communication between each connection. You have to use database storage, stream or file to send data between each instance. All of these methods are not very efficient.
It is using blocking I/O and this is where it hurts in term of performance and scalability.
You should look at non-blocking I/O technology for web server. They are all event-driven server which is something different from the PHP approach. Here are few example :
JBoss + Netty (Java)
Node.js (Javascript) - Google Tech Talk about it
Twisted (Python)
You need websockets or something similar.
http://www.orbited.org/
"Orbited allows you to write real-time web applications, such as a chat room or instant messaging client, without using external plugins like Flash or Java. It enables streaming networking for JavaScript without loading bars or page refreshes."
You can implement the chat as IRC or Jabber using Orbited.
Related
Lately, I have been doing a lot of research (of course googling :P) on building real-time application (like chat application). So far I have come across Elephant.io, Socket.io and Ratchet. And some of the terms I stumbled upon were web-sockets, bi-directional communication etc..
I am building an auction site where it involves countdown timer. I am trying to achieve something like when one user bids, the timer gets updated in all the client's browser without page refresh (something like server broadcasting the change of event to all other connected users).
The problem is, I am building the application with PHP (Pyro-cms). The server, where it will be uploaded is Apache-based server and does not support node.js. One of the most common stuff I notice was most of the real-time applications were utilizing node.js.
Is it possible to build real-time application using PHP , Socket.io and javascript only? or may be with angular.js?
I really cannot use the server that support node.js so have to completely rely on apache server. I even dont know if it is possible. If there is any resources, reference or tutorial, it will be very helpful.
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
I'd like to create an API for a project I'm working on, allowing developers to create desktop and mobile applications built around its functionality. One thing I've always wanted to learn how to do is create a stateless, push notification system, similar to Twitter's Streaming API.
Basically, I want to be able to notify users of any changes to the data in real time, or as close to it as possible. I know that this might be difficult on mobile devices, which is why mobile applications will probably be built to check for updates periodically, to save battery. However, desktop applications won't have that limitation. I'd like to avoid making the application ask the server if there is new information, and instead let the server tell the application that there is new data.
My programming language is PHP and my server is Apache. If I absolutely had to I could switch to Lighttpd or nginx, but that's an absolute last resort since it would require a lot of changes to all of my existing code.
I've read this article:
http://www.zeitoun.net/articles/comet_and_php/start
And tested it out, but unfortunately all that happens is my browser keeps attempting to load the page and never actually displays the time. I suspect this is because, for whatever reason, I've never been able to get output buffering to work on my server, unless I send 64kb (or more) of data. I heard that I had to disable gzip, which I did, and it still didn't work, so I don't know.
Have a look at some existing technologies to help you do this:
Tornado
Tornado is an open source version of the scalable, non-blocking web server and tools that power FriendFeed. The FriendFeed application is written using a web framework that looks a bit like web.py or Google's webapp, but with additional tools and optimizations to take advantage of the underlying non-blocking infrastructure.
Pusher
Pusher is a hosted API for quickly, easily and securely adding scalable realtime functionality via WebSockets to web and mobile apps.
Both are extremely fast and scalable, and I have setup both relatively easily.
Well you could do this in several ways, you could build in a poller at the client side, or you could use something like NodeJS. (http://nodejs.org/) or web sockets.
Yeah another good piece is
http://socket.io/
and
http://elephant.io/
some tuorials like this might also be useful.
http://www.phpbuilder.com/articles/application-architecture/optimization/creating-real-time-applications-with-php-and-websockets.html
I've been reading a few posts on here regarding polling and even had a look at Pusher although i don't want to go down that route and need some advice in regards of making an efficent notification system. How do facebook, twitter and other websites do this? are they using web sockets?
Polling
> Polling data from server - most
> efficient and practical way/setup
You should avoid polling because it is not efficient and also not real-time at all. Let's say you poll every 30 seconds and your server can handle the load without any problems. The problem then is that your data is not real-time. You could shorten the poll-interval (every second), but then you will have a very difficult time trying to scale your server.
But sometimes polling (smart) is also very nice, because it is easy to implement. Some tips I have for you are:
Don't use the database, but retrieve data from in-memory database like redis, memcached because they are much faster. That is the secret ingredient for most popular big players(websites) to run smoothly. Facebook has special purpose servers that use a lot of memory using memcached (5 TB in 2008 => Facebook has grown a lot since ;)).
If you can't install (probably should!) Memcached or Redis on your server you could consider using the hosted http://redistogo.com which is free for small sites.
The other thing to do is increment the poll interval using github's library to prevent server overloading.
> How do facebook, twitter and other
> websites do this? are they using web sockets?
Web-sockets
Some of these sites are using websockets, but that is only one of the many transports that they support because websockets aren't available in all browsers. In the future when all browsers support websockets that will be the only transport used (probably). Below I will give you a list of all the popular transports with a quick description:
websockets:
WebSocket is a technology providing
for bi-directional, full-duplex
communications channels, over a single
Transmission Control Protocol (TCP)
socket. It is designed to be
implemented in web browsers and web
servers, but it can be used by any
client or server application.
For the client side, WebSocket was to
be implemented in Firefox 4, Google
Chrome 4, Opera 11, and Safari 5, as
well as the mobile version of Safari
in iOS 4.2. However, although
present, support is now disabled by
default in Firefox and Opera because
of concerns over security
vulnerabilities.
xhr long-polling:
For the most part, XMLHttpRequest long
polling works like any standard use of
XHR. The browser makes an asynchronous
request of the server, which may wait
for data to be available before
responding.
This transport is available in every browser.
json-p long-polling:
A long-polling Comet transport can be
created by dynamically creating script
elements, and setting their source to
the location of the Comet server,
which then sends back JavaScript (or
JSONP) with some event as its payload.
Each time the script request is
completed, the browser opens a new
one, just as in the XHR long polling
case. This method has the advantage of
being cross-browser while still
allowing cross-domain implementations.
htmlfile:
provide a usable streaming transport
in Internet Explorer
flashsocket
XMLSocket is a class in ActionScript
which allows Adobe Flash content to
use socket communication, via TCP
stream sockets. It can be used for
plain text, although, as the name
implies, it was made for XML. It is
often used in chat applications and
multiplayer games.
Facebook
As you probably know Facebook does use PHP for there active development, but actually don't use it for any of there real-time elements on there site, because PHP is not designed to handle this properly (yet?). A lot of people get mad at me for saying this, but I can't help that it is the truth (even Facebook agrees). In PHP almost all function calls (C) are using blocking I/O which makes scaling real-time systems almost impossible. I read a blog post over here using non-blocking IO with PHP (quality?). In the past Facebook created the chat using Erlang which is also pretty popular for doing non-blocking IO. I myself find the Erlang code looking strange, but I still would like to learn it. Here are some links about Facebook using Erlang:
https://www.facebook.com/note.php?note_id=91351698919
https://www.facebook.com/note.php?note_id=51412338919
http://www.infoq.com/news/2008/05/facebookchatarchitecture
Also Facebook bought Friendfeed in the past and open-sourced there Tornado framework which is written in Python to do non-blocking IO.
It is no longer just the traditional
Linux, Apache, MySQL, and PHP stack
that make a site like Facebook or
FriendFeed possible, but new
infrastructure tools like Tornado,
Cassandra, Hive (built on top of
Hadoop), memcache, Scribe, Thrift, and
others are essential. We believe in
releasing generically useful
infrastructure components as open
source (see Facebook Open Source) as a
way to increase innovation across the
Web.
I assume they are also using tornado for some parts of there system now.
Other sites
Below I will try to list some popular frameworks(open-source) to do non-blocking IO:
Socket.io (Node.js): Socket.io is becoming a pretty popular non-blocking framework for node.js (1722 people are watching this project on Github right now). I really like Socket.io
Netty (Java): The Netty project is an effort to provide an asynchronous event-driven network application framework and tools for rapid development of maintainable high performance & high scalability protocol servers & clients.
tornado (Python): Tornado is an open source version of the scalable, non-blocking web server and tools that power FriendFeed.
> even had a look at Pusher although I
> don't want to go down that route
I don't understand your dislike for pusher because it is a pretty popular hosted solution. With this hosted solution you could started building scalable real-time service without any hassle with pretty good pricing (free if small and pretty affordable for middle range websites).
I was researching about websockets and came to know about 'Kaazing WebSocket Gateway'. Kaazing WebSocket Gateway provides complete WebSocket emulation for all the older browsers (I.E. 5.5+, Firefox 1.5+, Safari 3.0+, and Opera 9.5+), so you can start using the HTML5 WebSocket APIs today.
Please see this link
I would like to implement a mechanism which will provide a RESTful API that allows a client to register interest in a subject with a sever, and receive asynchronous notifications from the server after the interest is registered. In enterprise (messaging) architecture, this is known as publish/subscribe 'pattern'.
With desktop applications, this is readily acheivable - however with web applications, it is proving to be more difficult.
is there a (preferably open source) framework or library out there that allows the publish/subscribe pattern to be applied to web applications?.
Server side technology may be in any of the following languages: C, C++, PHP, Python, Ruby.
I am running on Linux Ubuntu 10.0.4
Have a look at the pubsubhubbub protocol: http://en.wikipedia.org/wiki/PubSubHubbub
Here is the source of the project: http://code.google.com/p/pubsubhubbub/
If you know in advance you'll have a lot of subscribers (people/applications) that want notifications on a certain subject while on other hand you'll have few different subjects consider a pull technology anyway.
RSS, Atom are quite successful even though they use pull. The reason: no need to have an administration on the server of people who are subscribed, to detect who is no longer interested (client offline for a long time) or having a mechanism to get all the data out to the subscribers.
Using push, you need to do very little on the server, while the clients will only pull a small amount of data everytime.
Pull costs slightly more bandwidth that's cheap anyway while it saves you a lot on CPU and software maintanance which is quite expensive.
I suggest you take a look at STOMP protocol, and its python clients (I use stomp.py). That should suit all your needs.