@BobRay, how hard would it be to take that code and save the tweets in a flatfile db or a new table in the MODX db?
Reason being like whistlemaker said, the whole idea of saving the tweets is to avoid having to request data from Twitter with every page load, and making it so that the script only requests data once every day, or once every 2 days, or however often.
While writing the files to the db, it could drop in a timestamp, and then let PHP compare now to the timestamp; if the difference is greater than the time declared as a cache time, then it can request data from Twitter, if the difference is not greater, than it can pull the cached results.
Also how hard would it be to put a timer and a program kill function? Meaning, if twitter takes longer than 1.5 seconds to respond, kill the script and pull from the cached results. This way, if twitter is having issues, the script doesn't get hurt from it...
Much better performance, as well as less reliance on Twitter, which may or may not be up and may or may not be speedy at any particular moment.
"Great spirits have always encountered violent opposition from mediocre minds." -Albert Einstein
Eesh my manners just aren't here today sorry.
@BobRay, it looks really good, and I'm excited to try it, and thank you! I'm implementing code a little later today or early next week that I can try to drop this in to and see how it works. Thanks!
"Great spirits have always encountered violent opposition from mediocre minds." -Albert Einstein
It should be fairly easy to save to a file. You can also get the post IDs of the tweets. $tweet->id) gets you a float and $tweet->id_str gets you the string as an ID. If you store the most recent ID, you can use the since_id parameter to get new ones since you last checked. I assume that you'd add the new ones at top and roll some old ones off the back.
------------------------------------------------------------------------------------------
PLEASE, PLEASE specify the version of MODX you are using.
MODX info for everyone:
http://bobsguides.com/modx.html
Oh I wouldn't think to even bother with rolling new ones in and old ones out. Just tell it to 'Get last 2 tweets, timestamp it, save them with the timestamp. Then, the next time the script begins to run, it checks now vs the timestamp, and if the difference is large enough, it gets the newer tweets from twitter, re-writing the file. The purpose is to display the latest tweets, not to keep extensive records of tweets, so no reason to make it complicated...
I'm probably not understanding something here....why would I want the post IDs of the tweets, and what are those? What is a float? The since_id parameter is part of MODX or twitter? Thanks in advance!
"Great spirits have always encountered violent opposition from mediocre minds." -Albert Einstein
Every tweet on Twitter has an ID number (a floating point number so it can be really big). If you include the since_id parameter in the Twitter URL, Twitter will only return tweets newer than the one with the ID you send.
BTW, you actually get a whole lot of information back from Twitter with the code I wrote above. Info on each tweet and info on the author of each tweet. The code is ignoring it, but if you uncomment the var_dump line, you can see it all.
------------------------------------------------------------------------------------------
PLEASE, PLEASE specify the version of MODX you are using.
MODX info for everyone:
http://bobsguides.com/modx.html
Got it, I'll have to play around with it and see what I can come up with. Thanks....I'll follow up when I follow up with the code!
"Great spirits have always encountered violent opposition from mediocre minds." -Albert Einstein
Hey BobRay, was this done in Evo or Revo?
"Great spirits have always encountered violent opposition from mediocre minds." -Albert Einstein
In his example he's using Revo snippet syntax
I know I saw that, but was wondering b/c I had mentioned I was working in Evo, so I wasn't sure if the snippet was done in Evo or Revo...thanks for the heads up...
"Great spirits have always encountered violent opposition from mediocre minds." -Albert Einstein