Jump to content

PHP Daily Counter


imperium2335

Recommended Posts

Not sure exactly how you plan to use this counter. But, you could also have the counter determined dynamically in the code. For example, if you wanted the counter to start at 0 and increase by 1 every 15 minutes you could do something like this:

 

$counter = floor((date('G')*60 + date('i')) / 15);

Link to comment
Share on other sites

Way I perceived it was a 'hits today' kind of counter.

 

Hmm...then I'm not sure how to interpret this statement

How can I do this without relying on visitors to the site to run the script?

How would you increment a hit counter without relying on visitors to the site?

 

IF the OP is only asking how to reset the counter without relying on visitors to the site it might make sense.

 

Even so, it would be helpful to know how he is storing the hit counter. Rather than running a cron job I would suggest storing the date along with the counter. Then the counter could be reset each day the first time it is incremented.

Link to comment
Share on other sites

I have gone for the option of having a browser open on our server which refreshes the page and runs the script ever 10 seconds.

 

Really? That seems like a very poor method of doing something such as this. If the browser on the server crashes (or starts consuming gobs of memory due to a memory leak) you will have problems. If you were to provide a little more detail as to how the counter operates we can provide a much more elegant solution.

Link to comment
Share on other sites

Does this site reside on a linux server?

 

If so, make a php file.

php file

<?php 
include('mysql_config.php');
$sql = "SELECT `hits` FROM `form_hits`";
$result = mysql_query($sql);
while($r = mysql_fetch_assoc($result)) {
echo $r['hits'] . "\n";
}
$sql = "TRUNCATE `form_hits`";
mysql_query($sql);
?>

 

Then insert this into your crontab.

crontab

MAILTO = admin@mysite.com
0 0 * * * curl --silent --compressed http://mysite.com/path/to/phpfile.php

 

Crontab quick reference

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.