Froskoy Posted September 29, 2009 Share Posted September 29, 2009 Hi, I have a page that gets about 1000 hits a day. The first time the page is viewed on a particular day, I should like to run a script which doesn't do anything else the other 999 times it is viewed. Is this possible and how do I go about doing it? Thanks very much, Froskoy. Quote Link to comment Share on other sites More sharing options...
redarrow Posted September 29, 2009 Share Posted September 29, 2009 what tell me more interesting, what u on about?, what you doing? what the domain name in question? Quote Link to comment Share on other sites More sharing options...
mattal999 Posted September 29, 2009 Share Posted September 29, 2009 Could do something like so at the top of the script: <?php // Connect to Database include("includes/connect.php"); // Select the row according to date $date = date("d-m-Y"); $query = mysql_query("SELECT * FROM firsthit WHERE date='".$date)."'"); if(mysql_num_rows($query) == 0) { // Run script and add new row include("script.php"); $update = mysql_query("INSERT INTO firsthit ('id', 'date') VALUES (NULL, '".$date."')"); } ?> Table structure: id (smallint - autoincrement) | date (could be varchar or date) Quote Link to comment Share on other sites More sharing options...
Maq Posted September 29, 2009 Share Posted September 29, 2009 Does it have to be triggered by the first request? If not, you could simply schedule a cron for run first thing each day. If that's not a possibility then you can use mattal's suggestion (as I don't know any that will work without querying the DB every time), but I would use a DATETIME type, not a VARCHAR. Quote Link to comment Share on other sites More sharing options...
Psycho Posted September 29, 2009 Share Posted September 29, 2009 If not using a database, you could use the same logic that mattal999 posted above but use a flat file to keep track of whether the script had been run that day (e.g. change the content of the file to the current date). Although, I would change the order of operations to update the trigger after the processes you want to run once have completed. Alternatively, you could create two files - one that is accessed by the users wich just displays the information and another which performs the scripting you want run once per day. Then use a cron job to schedule that script to run each day at a specified time. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.