I'm new to php. Please can anyone guide me through this? I have a php where I'm having some variables as sort of flags. When those flags are set/true, I start those services in my Blackberry otherwise not. My application keeps on listening to my php and when those flags are true, it starts the respective services, others are kept off. How can I achieve this? Thanks.
It sounds like you want push notifications.
If you do it by "listening" to a php page, you're going to have to repeatedly make requests to that php page. You could do long-polling, but that's not going to work very well on a cell phone... each time the connection disconnects, you need to connect again, and it's messy to write all that client side code yourself. PHP also isn't a great language for push notifications, because on the web-server side, there's no easy way to push information to php once php has a connection from your blackberry. Since PHP isn't multithreaded (in typical webserver configurations), you'll again most likely be busy-polling some notification in a file on the disk of the web server, rather than just receiving and handling a notification as from a message queue or socket/io connection.
Most phone development kits have built in APIs to handle push notifications. From what I understand, re-using these systems leverages existing architecture, meaning the phone only connects to one server, which saves battery life.
I've never done any blackberry development, but you should probably start by searching for information/tutorials on implementing push notifications in blackberry.
If I'm wrong, and you just want to be able to get configuration options for your blackberry app, then that's easy. Your php page just spits out the information in any format the client (blackberry) can read (like json, xml, key=value, whatever), blackberry parses it, and acts on it.
Related
I am developing an picture sharing application with messages. Now want to know how to make it instant just like Viber or whatsapp. The timer of more than a minute is not a good idea the user will have to wait for a long time for the message to arrive. And HTTP request every second will have a lots of overload on the server.
I have heard about the socket programming but not sure if it is the best way. Also how to implement that?
So the question is What is the best way of implementing this kind of application?
I am using IOS and PHP as a server language.
There are two approaches:
You can use your own protocol over any kind of socket you want (most probably a TCP or SSL stream), and then you need a server at the other end that keeps these connections open and send notifications on the right connections when something happens (new message...). There are probably existing frameworks for this, though all I can think of right now are more geared towards integration with web applications rather than native ones. Note that this will only work as long as you app is active in the foreground. This also means you will get as many simultaneous connections to your server as there are apps running, so you may have a scalability issue.
or you can use Apple Push Notifications to send notifications to the app that there is something new happening. You may include all the relevant data in the payload, or you may trigger a connection by your app to fetch the rest of the data. This will work both in the background and the foreground, though slightly differently.
You may also mix both: use APNs when your app is in the background, and you own connection when it is in the foreground.
I'm trying to find an easy way to implement push notification between PHP and Flash (AS3).
The flow is as following : i get a message to my external API -> i need to update my client regarding the changes he need to do without do pulling.
I know SmartFox server has the ability to do that but SmartFox is java based, but don't understand if i can connect to smart fox from php, and i can how would i do that.
If anyone can help, please do.
SmartFox Docs
I think that a SmartFox installation might be overkill for a notifications system alone. The SmartFox server maintains a socket connection with the SWF client, and pushes+pulls data that way, so a simpler solution would be to run a PHP socket server, with an AS3 socket client implementation.
There are a few examples of each end of this setup around the web, and some that provide a sample PHP server and AS3 client in combination, such as this one: http://www.kilometer0.com/blog/code/php-xml-socket-server/
Personally, depending on the amount of likely traffic and the degree of responsiveness needed, I might prefer to poll a regular PHP script from the client on an interval of a few seconds, and perhaps reduce these if there's been no user input for a while. That's certainly easier, but you specifically asked for no pulling, so feel free to disregard that!
I'm fairly new to XMPP and Openfire and am trying to get my head round the standard way of doing things.
I'd ideally like to send any messages received by a specific XMPP user, via POST, to a URL where a PHP script can then process the message. This would all happen on my local server / local Apache installation.
I've seen that with BOSH I can make a persistent connection listening for XMPP messages through PHP, however perhaps I'm mistaken, but it doesn't sound like a very stable way of doing things - I worry that I'd either end up with multiple persistent connections or my BOSH PHP script would time out and I wont realise. I also ideally wouldn't always have the browser open and running this script!
Can anyone point me in a sensible direction to start me off? Many thanks
Are you trying to create some chat using php, or want to intercept messages to certain user to do some custom work ?
Have you taken look at javascript for chat http://candy-chat.github.com/candy/
Maybe you will find there something that might help you move in right direction.
How to make php client to client, like the chat way ? One client connects and sends something to the other client and only he recieve not all clients.
Your Question?
If I understand correctly you want one-to-one(private) messaging.
Socket Programming using PHP
You need to learn Socket programming with PHP. You could start by studying this tutorial. This has scaling problems written all over it, because PHP does not have non blocking IO, proper thread model. I advise you to just use it for fun little projects.
Non blocking IO using PHP
You could try and use PHP-MIO. I have not yet tried this, but I guess it might scale. But then again from Apache(PHP) side you will have the same problems. But when using this from both sides it could work...
long-polling(blocking IO) using PHP
P.S: got bored so I have not completely tested this ;)
Download
Below I present two solutions(prototypes) which do NOT scale. One solution uses Redis pubsub. For this you need to install(compile) redis. For this you a POSIX OS is desired, although some people have ported it to Windows. You can also use the free redistogo.com instance. The Redis solution is the prefered solution. I have put everything in an archive which you can download from here.
I also give a solution which uses named pipes. This solution does not require you to use Redis, but instead this approach needs access to the file system. I believe that this approach should also work on Windows(You have to change the filename to windows-style). I would like for somebody to try this out :). I can not test this anymore, because I have completely switched to POSIX OS(Ubuntu) a long time ago.
Requirements
At least PHP 5.3 and preferable a POSIX OS, redis.
How to use
To use both solutions you need to open two browsers(Browser A/B). I assume you are using localhost for development and that you can access files from http://localhost/6646733.
point browser A to http://localhost/6646733/redis?me=somebodyelse&to=alfred you should replace redis with pipe when trying out named pipes.
Point browser B to http://localhost/6646733/redis?me=alfred&to=somebodyelse
In browser A type a message into the textarea, which will be sent to browser B.
In browser B read the message just sent from browser A
Solutions not using PHP
The solutions below scale.
Pusher(Hosted)
With for example the hosted solution Pusher you can do chat/messaging without the scaling nightmare. Pusher even is generous to provide a free plan. But be aware that the cheap plans do NOT offer SSL so the messages can be intercepted. You should never sent private information over the wire, when not using SSL. Users/developers have provided a nice little library to use Pusher from PHP. The problem with this approach is that you are not in control, but pusher is, but then again you don't have to worry about any details.
Socket.io(open-source)
I really like socket.io, but there are off course a lot of other solutions like for example tornado. You could use Redis to efficiently communicate between PHP and the other solution(socket.io).
I don't fully understand what you are trying to do, but you can use some kind of database and have it store messages that is sent to each user, and then have your client page refresh the chat part with a AJAX kind of query to update the chat. It will then behave simular to the new Facebook chat, where all messages are stored even the ones sent in normal chat and mail. So clients can mail and chat each other at all times, when they are online it will show in their chat and when thy are offline it will show up in their inbox. But this might not be what you are trying to do.
For implementing best Chat application, use jabber server and write clients using js/flex
http://en.wikipedia.org/wiki/Extensible_Messaging_and_Presence_Protocol
If it's not like chat but you want to send messages over without a server, you need both clients be server as well. A server will listen on a port for incomming connections. Write a daemon that spawns a new thread each time a client connects. Within this thread you handle the messaging.
Client A opens a connection to the server (Client B) and they can talk to each other. Or you let Client A become server and let Client B connect.
I have an existing app written in PHP (using Kohana framework) and I want to do long polling. From some things I read it seems that doing long polling with PHP is not advisable and using something like nodejs is a better choice. My question is what's the best way to integrate nodejs (or some other well suited tool for long polling) with an existing application?
For clarification my app basically is a browser plugin that you can use to send data to groups of other people. When that data is sent, I want the recipients, if they are online and also have the browser plugin, to instantly receive that data and be notified.
Possibly the best way is to let node.js listen to a port and to let PHP send messages to that port.
In Node.js you can just open a socket for listening and in PHP you can use cURL to send messages. The messages can be in JSON-format.
If the Node.js-part receives a message, it can forward it, possibly after some processing, directly to the long-polling browser.
I am creating a small hack that would allow you to do this with ease. It is in a very early stage but it has enough code for it to work: https://github.com/josebalius/NodePHP
I plan on updating the readme later today.