Best methods of implementing a sync api - php

I searched everywhere for this but couldn't get a proper answer.
I'm building a client app (angular) and an api (php). Periodically the server and the client's indexed db needs be in sync.
What i have done so far.
once every 10 minutes the clients makes a post ajax call to the server api
it send two prams. a. array of data which is a log of changes made to the documents . b. an array of ids which the server should return its documents
the server will copy all the data in the array to a collection for later processing. and will return a list of id which successfully copied. the server will also return the documents for the requested array of ids
back in the client the angular app will update the documents the server responded and will save the successfully saved ids to the indexed db which will again be send int the next api call.
This is a very simple routine. i just wanna know are there any other methods or standards?

you need to use $timeout or $interval service. if you are using $timeout service in the succuess callback again initiate $timeout service to the api kind of recursive, this will update the same scope model every time and your UI will be updated according to the latest data

Related

Does the Filemaker API implement caching for _find requests or portalData requests?

I am rewriting an application which uses a Filemaker database. Historically, a PHP script had a PHP SDK connection to Filemaker. I am converting it to use the Filemaker 17 API.
During development I am creating a new record, and then displaying a list of records. After creating a new record, the old system (using the PHP SDK) will display the updated list immediately. The new system I'm developing will not.
After a few minutes, the new system (using the Filemaker 17 API) will show the correct list. It seems to take 5-10 minutes.
All of this is happening through the use of portals.
I'm using the Symfony PHP framework. I've tried clearing the Symfony cache.
I've also tried appending a UNIX timestamp to the _find URL of the API call. It still returns me a list, but it's a stale list.
I'm using the 'cache-control: no-cache' cURL option, as well.
I've scoured the FM 17 API documentation, but can't find anything pertinent.
Is there a cache that the FM API implements? If so, how do you disable that?
I expect the list to update immediately through the FM 17 API.
-- Updated --
If I manually update the record containing the portal data, the list returned from the API works instantly. Is portal data cached?
To ensure there is fresh data you could close the API session and start a new session.
When your code is done accessing the hosted database, use an HTTP
DELETE method with the sessions URL specifying the name of the hosted
database and the access token for the session. If your code does not
log out of the database session, the access token becomes invalid when
the FileMaker Data API session times out 15 minutes after the last
call that specified the token.
https://fmhelp.filemaker.com/docs/17/en/dataapi/index.html#write-fm-data-api-calls_connect-database_log-out
Or as part of your find you could run a script in the script.pre-request as part of your _find that will refresh the portals on the layout. E.g. using the "Refresh Portal" script step. The "caching" behaviour that you see may just be that the layout is not updating for that Data API session, and the layout needs updating.
You can run FileMaker scripts as part of the find request by including the
script.prerequest, script.presort, and script parameters in the
request body.
https://fmhelp.filemaker.com/docs/17/en/dataapi/index.html#perform-a-find-request
You could also do a find directly on the Events table using your Person Key.
Also as a final note, if there is some sort of uncommitted record somewhere, from an API script call that doesn't finish with a commit, or otherwise, then the data may not be showing in the portal yet.
(Note answer edited with fresh information)

linking android application to the mysql database phone and link the info as well

Hey guys im faced with a challenge of linking my localhost mysql/php when adding something in a form that form should also be linked with my android application.
ex. I have made a form for the admin whereby they could add a new bus route and it will be stored into their database using php mysql in localhost server now that new route should also be linked to my android application it should display the new route (My android application uses sqlite database so two different database here) so when users use the application when they search for new route it should also display as well
How can i go with that? any ideas please im really stuck in this
thank you
Well there are generally 2 approaches to follow when you want to 'Sync' your web database to your mobile database
Push Notifications: You could send a push notification to all your users, whenever a new route is added to the mysql db. When the notification is received by your app, (it's not necessary you show the notification to the user) you could just ping the server for the new route, or you can send the 'route' in the message part of the push notification if you can, and then add this new route to your sqlite database.
AccountManager: Using the AccountManager is the preferred method when you want to Sync your data. The AccountManager uses the SyncAdapter to Sync your apps data with it's cloud. When Android pings the servers of other apps for syncing, it pings your app's server too, and syncs your data. This method also takes care of issues like, if the internet connection was not working when it was intended to sync, so android will schedule the next sync soon.
To provide a good service, you should take a look at a client-agnostic API architecture.
In this architecture, you have a PHP/go/whatever-written API, that can or can not be REST (but it's reccomended), that will provide, given a HTTP petition, the desired result.
Using PHP in the simplest way, you should create different .php files, one for each action ( www.myserver.com/getRoutes.php, www.myserver.com/getRouteDetail?routeId=3), and make those PHP files query the MYSQL database and return (echo) XML / JSON / Raw text.
this should then be parsed by your mobile application, and added/updated to your SQLite database.

Send data from a web server to an android app

I'm trying to understand how I can send data from a web server to my android app. This isn't a request/receive type question, what I am looking to do is basically have my web server (say for example www.example.com/index.php) send a data (like a string for example) to my android app. Now, this data can be sent anytime, it isn't something where a you click something on the app to receive the data, but rather, when the server is wanting to send data, it sends the data, and my app picks it up. Now I'm not looking for my app to be listening for this data every second, an interval of 5 minutes or so is fine.
The question being, how would I achieve something like this? How can I send a string containing "Hello World" to my app? I know PHP, and I know this has to be done using POST/GET, and of course I know there will probably be some type of listener, service, or something of sort on the android side listening for this data, but I just want to know how I can approach this. What should my setup be?
If someone can provide some link or code to send a basic String message, then that would be more than enough for me to learn from.
There is two best approach you can follow.
from server to app: in this case make corn job(timer service) which send push notification to android app. when app get push notification create one background service which download any data from server.
Note: if you have small text with limit of 100 char then no need to create service just send using push notification
fetch data from server: in this case make one background service(auto start service) in android app. which run within some interval period like 1 hour or more(whatever your requirement). that service fetch data from server.(in this case android app eat battery of user device because of background service)
i will suggest you to use 1st approach because its easy and best way(in case of performance) your server do everything & android app have to just receive data.
how to implement push notification best tutorial using PHP & android(its old but just read official docs)
For this you need implement android push notification.When you send the data from php server then the application get this data automatically.
yes if you want to send data into your app from server side to app without calling web service on click of button you will use cronjob which run on defined time from server side(As i.e : if you want to run it every five seconds or minutes it will possible you don't need to call it from app side).

Why am I getting out of date or slightly incorrect data back from the Linked in API when querying for job listings of a certain company?

Using PHP and Curl, I've successfully gotten through the OAuth process to gain a token using the Linkedin API. When making an API call to get a listing of a specific company's job listings I get truncated and incorrect information back. I'm only getting 5 of the 7 job listings and one of them doesn't even exist when looking at the job listings on linkedin.com.
I've determined that this is not some caching issue on my side because my application data matches the data given by this tool: https://apigee.com/console/linkedin
This is the API call I'm making:
https://api.linkedin.com/v1/companies/{COMPANY_ID}/updates?event-type=job-posting&format=json
I think I may be using the wrong API call as it looks like I'm only getting updates and not the complete list of jobs. I can't find any other way to query for jobs though.

Unable to identify issue with Ajax call to Yii API getting no response headers

Overview
I'm currently working on a jQuery/HTML5 project that displays web performance data with a series of charts using an internal API to retrieve the data. The API is powered by Yii, but I am not working on it, so i cannot change or experiment with it myself.
Basically I am hoping someone can help identify if the API is the root cause of the problem or if it's a problem with the Ajax in my jQuery being incorrect.
A small explanation of the process my application goes through...
Application loads, uses user details to authenticate with API. Receives API Key from API.
After the key has been retrieved, several calls are made to retrieve data from the APi to display as the web performance data.
At set intervals, a generic is called to the database to check that the API Key has expired or not.
If the key has expired, it makes another request to the API for a new API Key as stated in step 1. If there are any problems with gaining an API key, this is when the user gets kicked off.
Restart cycle excluding getting the data.
Problem
All Ajax calls are made to the are crossdomain as both the project and the API are on separate sub domains. These are done using JSONP and a jQuery callback.
The problem I am having is that when I need to authenticate if the key is valid or not, if it is no longer valid, the API returns a 401 error which my Ajax does not register. If i view the API URL in Firefox, I can see the returned Json data, wrapped in a callback, but when I check firebug it says there is a request, but no response.
Basically when the API returns data that is not 200 OK, it doesn't send a response header at all.
However I have manually called the API using cUrl in terminal, and have received a response header, as well as in Google Chrome.
If someone could tell me if this is a well known issue with Firefox/jQuery or if this is a problem with the Yii API I would very much appreciate it.
Try adding this before your ajax call:
jQuery.support.cors = true; // force cross-site scripting in IE

Categories