Please help me write a PHP script that publishes Twitter updates at pre-specified times.
I'm working on a script that will update Twitter with reminders about upcoming shows at a music festival, building on
lodev's idea
here.
I've currently got
this script, which calls a text file structured like in this made-up example:
XXXUPDATE SponsorCo Stage: THE BEATLES in 30 minutes XXXTIME August 21 2009 21:30 +0200 XXXDONE 0 XXXENDLINE
XXXUPDATE MegaCorp Stage: ROLLING STONES in 30 minutes XXXTIME August 21 2009 22:45 +0200 XXXDONE 0 XXXENDLINE
Proprietary format, I know. :) There are six Twitter accounts right now for separate concert stages, more may follow.
All six separate scripts are called from a Ruby file via pycron, every minute. I understand that's plenty often and I don't really need that kind of temporal resolution, but it uses relatively few processor cycles so I'm not really complaining.
As you can see in the PHP code:
if (($now <= ($utime + 30)) && ($now >= ($utime - 29))) {
if ($update[3] !== 1) {
When an update is ready for publication it should, theoretically at least, satisfy the first "if" statement and be published. The second "if" checks a "done" flag in the text file which I have as of yet not used (i.e. they're all set to 0 and the current code doesn't amend them).
Now, I "stress-tested" this with some test updates on all six accounts, including many simultaneous ones (carrying the same timestamp) on the different accounts for ten minutes with six (one for each account) every minute, and out of maybe a hundred-something tweets (I ran multiple iterations of the test) only one was dropped, i.e. it was in the text file but was not published.
Even one dropped update is unacceptable to me, and I strongly suspect I am Doing It Wrong. But how? The problem basically boils down to the following question:
What better method would there be to push out the updates reliably using the server config I currently have (XP, Apache, PHP5, Ruby, pycron), very preferably without using databases?
When it comes to scripting I really only speak PHP and a little JavaScript: even the (very basic) Ruby script was kindly provided to me for a different project.
So there's just too little time before the event to learn a new language or start out with MySQL or whatever before the event, and I'm not really eager to change to different software or change my server configuration (or set up another box) just for one-off project that will last just a few days. This is just to say that it's not due to an unwillingness on my part, but rather due to practical considerations.
If anyone could offer their insights I would be ever so grateful. Thanks in advance, guys.
posted by Rhomboid at 7:05 PM on July 29