FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » mktime() changes days when it should't
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: mktime() changes days when it should't [message #172416 is a reply to message #172415] Thu, 17 February 2011 01:49 Go to previous messageGo to previous message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma:
Senior Member
On 17/02/11 00:51, TAXI wrote:
> Sorry, I have forgotten someting:
> Bevore somebody asks why I need this: I want to write a script which
> does an action every month. For that I save the timestamp of the last
> execution and now I need a save way to check if one month is over. But
> couse different months doesn't have the same amount of days I can't
> simply count the secounds 30 days have and calculate with this.
>
> Am Thu, 17 Feb 2011 01:43:39 +0100
> schrieb TAXI <taxi(at)a-city(dot)de>:
>
>> Hi,
>> I write this couse of http://bugs.php.net/bug.php?id=54005 - As you
>> can see Derik says it's not a bug (in PHP itself) and links me to
>> here for support.
>>
>> P.S. Couse of Deriks last sentence I changed the script so that it
>> passes 0 as hour to mktime() but that doesn't change anything.
>>
>> P.P.S. Sorry for my bad english. :)

The best solution is probably using crontab to schedule your job to run
at the same time each month, eg 03:27 on the 3rd

Failing that, you could use a semaphore file and the getdate, filemtime
and touch functions, like this:

<?php

$sf = "semaphore-file-name";
$newmonth = false;
$last = @filemtime($sf);
if ($last) {
$then = getdate($last);
$now = getdate();
if ($then["mon"] != $now["mon"]) {
$newmonth = true;
}
}
else {
$newmonth = true;
}

if ($newmonth) {
touch($sf) or die "unable to modify file\n";
// do once a month stuff
}

?>

Rgds

Denis McMahon
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Almost done - Just need a way to assign a variable
Next Topic: Grate opportunities to earn money from online!
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Oct 05 21:42:50 GMT 2024

Total time taken to generate the page: 0.04600 seconds