I am looking for a solution for PHP and comet. I would like to make a chat using Ajax to send the message. I call the function using jQuery and send data, it is simple.
But the problem is in retrieving new messages. How to retrieve messages using the new solution comet? I need a simple example.
I am looking for a solution for non-commercial use - for free.
In short, I would tell you to use Node.js as your backend technology.
Here's a more lengthy explanation: Creating a live checkers-like web app with PHP, JS, CSS and HTML?
if you're set on using php, you can use a comet server which will sit on top of apache (or whatever server you prefer) and proxy any non-comet requests to it. I've used one called streamhub which is written in java.
Related
I have made a dating website where I have use one to one chatting application like facebook. When one user send any message to another user it showing into their popup chat box, but I have done this using ajax. Which I have run in every interval using javascript setInterval function. But I think the process is not optimize one. I don't want to make unnecessary request to the server each time, rather it only trigger when there is some new message for that user. Is there any other way to do it or any other protocol which using by big site like facebook, gmail?
You could do this using WebSockets, but that requires both a server implementation and a web browser that supports it.
Another technique is to use Long Polling, but again, this requires work on both the client and the server. The advantage is that this is a cross browser compatible technique.
I agree with Josh that WebSockets would be worth looking into, however if you don't have access to the server you could use something like Firebase for the back end.
https://www.firebase.com/index.html
Read into Long Polling. It's what facebook uses. Basically your client makes one Ajax call and nothing gets returned until there is data to push to it. I'm pretty sure it requires some custom server configuration so if you're developing on shared hosting it isn't going to cut it. Long Polling would be the right, albeit, more complicated way of doing this if efficiency is what you want.
Server-Sent Events seems to be another option.
A chat example: http://motyar.blogspot.com.es/2012/01/simple-chat-application-with-html5.html
Documentation: https://developer.mozilla.org/en-US/docs/Server-sent_events
I'm tried to implementing a live notification which is like the facebook newsticker and the notifications(on top). I was wondering what's the good solution to archieve this. I implemented an chat application before which I fired AJAX GET request in certain time to archieve the realtime, but it seems not good. I checked facebook using firebug, there is no GET request fired(or it is hided?)
Now here is my scenarion:
In main.php
I have a live ticker and a notifications button.
In bulletion.php and User.php
When I perform an add user,it will go heading to the bulletin or user.php.
How can I get informed in main.php when bulletin.php,user.php successfully created in database?
I checked this question as well before I asked.
notification system in PHP/jQuery
Realtime and php?
I was wonder,what's is long poling Ajax and session-based notification.How it can be archieved? I know Node.js can be good in implementing realtime, can it combine with PHP? and memcached ?
Any can provide sources to refer or example might be good.Thank you.
As a side note, PHP isn't really the best language to use when it comes to push notifications, it's really built around typical get/response kinda flows.
I use PHP for all my page stuff, but when it comes to push notifications of any sort I really like http://www.nodejs.org/ and http://socket.io/ to go with it. They're very easy to get setup, and will play well with you using php for the majority of your work, then using node to deal with push notification kinda stuff.
Have you thought about using HTML5 WebSockets? Have a look at EventSockets and the kickstart project on Github.
I've had much success with the server-sent events standard. It's very simple and works perfectly but it's only supported in modern browsers.
Meteor is a comet server using PHP and JavaScript to push data to browsers. It's very slick and worth a look, although it may be a little hard to setup/implement.
Edit: Quick demo here
I want to write a PHP script that performs a routine task in a web app I use. I am trying to figure out the easiest way to submit a form, click a link, and get some information. What's the easiest way to do this (keeping the session open, etc.).
Javascript would be a better solution than PHP. You can use it in tandem with PHP to submit a form that references the same page, ie. <form method='index.php' action='post'>
If method is GET then you ought to be able to work it out form the URLs of a few real world attempts.
It POST then you are probably SOL unless it's your own web page./app and you know what $_POST it expects ... unless you find a tool to snoop your HTTP traffic and get the POST info from observing a few real wrold examples.
You can use CURL in PHP to simulate submitting data, clicked links, etc., I suppose, but a client-side scripting language like Javascript--as opposed to a server-side language like PHP--is more suited to what you're describing. I'd need more info to give you a specific example.
You will not be able directly emulate those events in PHP as web apps use Javascript on the client side and PHP is a different language and operates on the server side.
Firstly, I would see if there is an open API available for the web app you're wondering about, e.g. Gmail: http://code.google.com/apis/gmail/ . Not all APIs can do what the web app can do, so you'll need to check the documentation to make sure the API does what you want and has an easy way to interface with PHP.
The other option is to essentially reverse engineer how the web app communicates with it's server. Most all web apps operate by sending POST or GET HTTP data in some sort of serialized format like XML, JSON or text. You can use something like the Firebug add-on for Firefox to view POST/GET data. If you know what the server sends to the client and what the client sends to the server, you can essentially write a script using something like CURL to emulate the client in PHP instead of JavaScript. This would take quite a bit of work and probably involves a lot of trail & error.
is there a way to write a program in php or javascript that can load a flash file and interact with it? (click on buttons and such)
JavaScript
Here's a good example of Flash/JavaScript interaction using the YouTube Chromeless Player.
PHP
While you could use a query string to retrieve data from a php file or have a PHP file pre-populate FlashVars you can also use PHP with amfPHP for more robust database interaction.
ActionScript
Maybe these links will help:
Basics of using the External Interface or External Interface
There are many ways to work server/client/flash interactions into your presentations, but for what purpose would probably be the question you should be asking. I've developed a chat client that interfaces with a jabber server through java and in turn with a Sony MMPORG game. There are many interactions between the client(browser), the server(s) and of course flash. Considering it was a flash application the interaction needed to be there in order to make the entire experience a lot more intuitive and useful for the end-user.
You can see the screenshots of this client here:
EQ2 Web-Chat Client - Javascript/Actionscript/DHTML by DrLouie - Jabber/Java Communication by PC(Pierce Courtney)
Unfortunately you cannot access the live client unless you have an active Sony Station account for EverQuest 2. Keep in mind this was developed way back in 2004, so if it was possible then, it's a lot more possible today. It's a fun way to develop flash interfaces! Even more fun is finding the possibilities of flash/javascript/server interactivity, which tends to be somewhat limitless to an extent...
Look at the ExternalInterface if you are using Flex.
http://blog.flexexamples.com/category/externalinterface/
Yes, you can load a flash file (.swf) into html document and make it interact with php, but! flash is the responsible of the interaction, sending data to php, so the swf file should do it, using the loadvariables() function.
good luck!
Can anyone give me a good and simple example of the comet technique using PHP?
I just need an example that uses a persistent HTTP connection or something similar. I don't want to use a polling technique, because I have something like that set up and not only is it difficult to work with and manage its a big hog of resources. Also I am using IIS7 not Apache.
A good example would be really helpful so I can move on from this ugly polling technique.
You should use polling, or use a web server which is specially conceived for long requests and COMET, with a good JS backend:
function listen() {
$.get("/mylongrequestfile", {}, function(data) {
$("#mydiv").html(data);
listen(); // then launch again
}));
};
Remember that COMET is "wait for data, if there's data return and exit", so JS backend will have to parse the data and re-launch the process of asking the server.
In this example, if there is a server side problem or just a disconnection from the user side, the entire process will be broken (the function is only called if the request is successful)
Check this out: How to implement COMET with PHP.
This is not using JQuery. It is made using PHP and Prototype. It is very easy to understand. I think you can made JQuery script easily after viewing this.
I have a very simple example here that can get you started with comet. It covers compiling Nginx with the NHPM module and includes code for simple publisher/subscriber roles in jQuery, PHP, and Bash.
http://blog.jamieisaacs.com/2010/08/27/comet-with-nginx-and-jquery/
A working example (simple chat) can be found here:
http://cheetah.jamieisaacs.com/
Never having used this technique and studying the Wikipedia article on the topic, "Long Polling" seems like the only viable solution. It sounds pretty simple to implement by infinitely looping and sleeping a script on the server. There's some actual code in the HTTP Streaming page linked to from the Wikipedia article.
Have you tried any of this and stumbled on specific problems?
Check out this demo video for implementing Long Polling ( comet )..
It might help you all
http://www.screenr.com/SNH
You can take a look at this article, it's a really good start to understand comet programming concepts.
You will find two examples on it. The first one use the iframe technique whereas the second one use a persistent connection.
For IIS, there's WebSync. Since you're using PHP, however, you might be better off with WebSync On-Demand. Either one will give you the server-push you're looking for, and is simple to use. Check out this question as well, which is basically what you're after.
Here's a simple example of WebSync On-Demand in action using no scripting language. Simply open in two windows, and see the publish/subscribe in action.
To publish from the server, you can use the PHP api.