chidge
05-24-2009, 12:58 PM
So here is the scenario:
The API I am calling is twitter and this is a self rolled twitter display feed. I wish to have a feed which will display data but also remove data from my CACHE DATABASE if it is removed from twitter.
I use CRON every 2 minutes to call an API using cURL. This API sends me back and XML file, I then pull out the information from this XML file and put it in an ARRAY. This array is then inserted into MYSQL. All good.
What I want is say on the second call to the API and the subsequent returned XML->ARRAY, I wish to compare the data held in the DATABASE with the data from the second call to the API. If the data is different then I wish to
A. insert any new data and
B. delete any data which is now not present in the second API calls XML->ARRAY but is present in the DATABASE.
So this is all good, but what I need advise on is the best way to do this. Please consider this is not going to be much data but I obviously want it as efficient as possible. (10 records at most - it also means I am not storing redundant data in my DATABASE which won’t ever be shown on my site)
So the way I see it is, I can either just delete all the table contents in the MYSQL DATABASE and insert new contents each time (apart from the first time). Or I can compare the information I have in the DATABASE with the information I have in the API->XML->ARRAY and then either delete from the DATABASE if it isn’t present in the API->XML->ARRAY or insert it into the DATABASE if it is present in the API->XML->ARRAY but not in the DATABASE. (This could involve three MYSQL statements)
Any thoughts? and any thoughts on the compare array code? Should I use array_diff or just simply compare the two arrays with ==. Any thoughts on the MYSQL code is there a way to compare things like this inbuilt?
Thanks in advance for any advice.
The API I am calling is twitter and this is a self rolled twitter display feed. I wish to have a feed which will display data but also remove data from my CACHE DATABASE if it is removed from twitter.
I use CRON every 2 minutes to call an API using cURL. This API sends me back and XML file, I then pull out the information from this XML file and put it in an ARRAY. This array is then inserted into MYSQL. All good.
What I want is say on the second call to the API and the subsequent returned XML->ARRAY, I wish to compare the data held in the DATABASE with the data from the second call to the API. If the data is different then I wish to
A. insert any new data and
B. delete any data which is now not present in the second API calls XML->ARRAY but is present in the DATABASE.
So this is all good, but what I need advise on is the best way to do this. Please consider this is not going to be much data but I obviously want it as efficient as possible. (10 records at most - it also means I am not storing redundant data in my DATABASE which won’t ever be shown on my site)
So the way I see it is, I can either just delete all the table contents in the MYSQL DATABASE and insert new contents each time (apart from the first time). Or I can compare the information I have in the DATABASE with the information I have in the API->XML->ARRAY and then either delete from the DATABASE if it isn’t present in the API->XML->ARRAY or insert it into the DATABASE if it is present in the API->XML->ARRAY but not in the DATABASE. (This could involve three MYSQL statements)
Any thoughts? and any thoughts on the compare array code? Should I use array_diff or just simply compare the two arrays with ==. Any thoughts on the MYSQL code is there a way to compare things like this inbuilt?
Thanks in advance for any advice.