Sending data through php page from android form - php

I am helping one of my friend in his android app assignment. Here is the problem statement given in his android assignment.
Statement:- There should be proper implementation of POST method with queue to accommodate the data request even when device is in offline mode and execute data sync request from queue as soon as device is online again.
How this task could be done. Correct me if I am wrong, I am thinking that this requires to be done using SyncAdapter. If I am correct and if it has any other way then suggest the same with a tutorial link for implementation.

Yes, indeed you need to use SyncAdapter. Read more here.
Logically, you need to have a message queue, where you push new messages based on user events and possibly other events as well and you need to pop the messages from there and pass to SyncAdapter.

Related

sending automatic push notification from mysql to android mobile

I have a database that contains some data and i want to get notified automatically on my mobile app if any value in the database is changed without having to check the database every certain time,i have tried many methods and viewed several tutorials but it leads me no where,any help ??
This is not going to be possible with only database. You need to write down an RESTful API which your app needs to poll to look for changes.
Ideal way of doing it is using GSM to push notify your app when ever you change something in your app. This will again require PHP/ASP/NodeJS etc... There must be some way you are updating your database? This should go exactly there.

Update app data from server (Swift)

I need some help with refreshing data. I have an app in Swift 2.0 and I want to the server send an action and execute a method in the app. I already try with push notification and It works greate but if the user disable the notification the method still execute? and according my knowledge this method is only execute when you press the notification. What is the best way to acomplish this?
I am trying to avoid that the app constantly request data from the server.
My server is in PHP.
Thanks!
I think you can use protocols/delegates.
Delegates are good ways to be notified only when needed and and alternative to notifications.
Go check for more here :
https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Protocols.html
With this scenario I think we have these locations to request for updates:
At appDelegate, overriding applicationDidBecomeActive, called when the app becomes active in foreground.
In the view didAppear from the main view from our app (the first view that appears when we open our app).
Both options make more requests to the server than they should, but maybe the 1st is the least costly because is called just when app becomes active, and this is a good moment to check for updates.

delay websocket updates and show the message later on?

I have an app where basically players challenge each other. At some point their challenge completes and I need to provide them (both of them - there are two players) with an update message, like 'Hey, you won and got 100500 points'. And vice versa - "Hey You looose"
I use websockets and pusher api to tackle the live updates, this works perfectly when player is "online". But what if they are not? The way to go for me looks like I can still handle the event with pusher and instead just displaying the message, I can store it to db to table challenge_notifications with fields messages and seen = 0. it's ok, but what would be the best way then to show this to the player when he comes online next time? I don't want to have ajax request on every page load checking to see if there are any unseen notifications for the user.
I probably somehow need to fetch all pending notifications only once, when they get online?
I use Laravel 5 for my backend.
There was a recent post on the Pusher blog about how to detect if a user is online or not using the Pusher HTTP API: Enabling Smart Notifications with Pusher and SendGrid.
The example uses SendGrid, but you could instead store the update to a database, send them a Push Notification, an SMS etc.
what would be the best way then to show this to the player when he comes online next time?
I guess there are two forms of "coming online":
The user is no longer on the site and has to navigate to the site. In that case as the page loads you can query the DB and serve them up any missed notifications directly (this would seem the easiest solution). Or, if it fits your app architecture, make a single AJAX request when the page loads to get any missed notifications.
If the user has gone offline due to them being mobile or having a bad network connection. In that case you can bind to the connected event using pusher.connection.bind('connected', function() {}); and then make a query to see if they've missed any notifications.
In summary: it would seem that querying the DB for any missed notifications upon normal page render (on the server) would be the simplest solution and wouldn't required much resource usage. But there are alternative mechanisms of delivering a notifications (email, SMS) if they're not online.

NodeJS with PHP application and user session

I have a PHP application (with Symfony2) and I need to let my users talk, and other tings, in real time (with socket.IO).
Let's focus on the chat mechanism : A logged user can talk with an other logged user (logged with FOSUserBundle in Symfony). When the user sent a message, it must be saved in MySQL and sent in real time to the other user. So the message is linked to two users (a sender and a receiver) in my MySQL database.
So I have two possibilities :
I use PHP to store messages :
I have an event on the click "submit" and call a PHP url with AJAX
If my PHP return "OK" (so he correctly added the message in database), I emit a Socket.IO event -> let doctrine deal with datas and symfony with my user
On NodeJS side, I have a listener on this event and I sent the message through Socket.IO with an other event
I use only NodeJS :
How can I log my user on PHP and NodeJS side ?
I need to use a different database for datas in real time ?
How can I share my users between NodeJS and PHP ?
I don't know what is the cleanest solution, if someone can help me.
Thanks !
Can be done using a common data store like redis to store user sessions
Check this link for reference
http://simplapi.wordpress.com/2012/04/13/php-and-node-js-session-share-redi/
Also check
http://www.slideshare.net/leeboynton/integrating-nodejs-with-php-march-2013-1
Which gives you an overview of how sessions can be shared using a common in-memory data store and some sample memcached code.
WebSockets
If you are using nodejs just for the WebSockets part, I'd suggest not to because then you'd have to replicate your user authentication logic in nodejs as well
You can instead do WebSockets in PHP using some library like http://socketo.me/
As far as storing the messages in MySQL goes
Your first approach of making an AJAX call to store the message in database, waiting for the response and then emitting a SocketIO event would lead to a sluggish chat experience.
I'd suggest you store messages to MySQL through NodeJS (asynchronously)
On a side-note check https://github.com/kyle-dorman/ChitChat.js for adding real-time chat functionality to your website.

implementing chat system php, obj-c, and mysql

I am a newbie API developer using PHP and we have a new client who wants to include chat system in the app that he wants to develop. I already created the native way by creating a table in mysql with sender, receiver, message, time_stamp field and I already created a set and get API call for Messages. But the client seems not satisfied because by default it is not real time. My front-end developer just call the GetMessage() on an X seconds.
What I want is to make it real time just like what Facebook or Skype app do. When new messages was inserted in the database the server will just poke the app that there is a new message via push notification I think? So in that case the app will not get messages on every X seconds. So basically once I hit the send button, on the other side, the receiver will just see it synchronously.
Take a look at something called triggers. They are activated in mysql when insert, update or delete-event occurs. An important thing though is that SQL has to used for triggers to be executed. The triggers would not execute from external api's.
You might for an example set some value in a table that tells that a new message has arrived for a certain user when a new insert is made into the db.
Starting points:
http://dev.mysql.com/doc/refman/5.0/en/triggers.html
http://dev.mysql.com/doc/refman/5.0/en/faqs-triggers.html

Categories