Note that there are some explanatory texts on larger screens.

plurals
  1. POPreventing a site-wide double submit
    primarykey
    data
    text
    <p>I was having a hard time figuring out a good title for this question, so I hope this is clear. I am currently using the TwitterOauth module on one of my sites to post a tweet. While this works, I need to set a limit to the amount of tweets submitted; <em>just one each hour</em>.</p> <p>Note: I do not have the option to use a database. This is paramount for the question.</p> <p>I have incorporated this as follows, in the PHP file that handles the actual posting to the Twitter API:</p> <pre><code># Save the timestamp, make sure lastSentTweet exists and is writeable function saveTimestamp(){ $myFile = "./lastSentTweet.inc"; $fh = fopen($myFile, 'w'); $stringData = '&lt;?php function getLastTweetTimestamp() { return '.time().';}'; fwrite($fh, $stringData); fclose($fh); } # Include the lastSentTweet time include('./lastSentTweet.inc'); # Define the delay define('TWEET_DELAY', 3600); # Check for the last tweet if (time() &gt; getLastTweetTimestamp() + TWEET_DELAY) { // Posting to Twitter API here } else { die("No."); } </code></pre> <p>(initial) contents of the <code>lastSentTweet.inc</code> file (chmod 777):</p> <pre><code>&lt;?php function getLastTweetTimestamp() { return 1344362207;} </code></pre> <p>The problem is that while this works; it allows for accidental double submits; if multiple users (and the site this script runs on is currently extremely busy) trigger this script, it happens that 2 submits (or more, though this has not occurred yet) to Twitter slip through, instead of just the 1. My first thought is the (although minute) delay in opening, writing and closing the file, but I could be wrong.</p> <p>Does anyone have an idea what allows for the accidental double submits (and how to fix this)?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload