note 57714 added to function.strtotime

From: Date: Wed, 12 Oct 2005 04:08:54 +0000
Subject: note 57714 added to function.strtotime
Groups: php.notes 
Request: Send a blank email to php-notes+get-96879@lists.php.net to get a copy of this message
I had a partially-written PHP app I started on v4.2.*, and it relied on the pecular behavior of the 'next' keyword in strtotime(). But, when I upgraded to 4.4.0, certain pages caused apache to spin out of control (i.e, 90%+ CPU usage!) This is because the 'next' keyword behaves differently in versions after 4.3.0 (or perhaps even previous versions, see the changelog: http://www.php.net/ChangeLog-4.php for more info.) I was testing in a while loop like so: $weekday = "...some arbitrary weekday..."; $now = strtotime('now'); $prevtime = strtotime( ... some random past date ... ); while ($prevtime < $now) { ..do stuff.. ..more stuff.. $prevtime = strtotime('next $weekday', $prevtime); } that used to work, since 'next' would just add a week to $prevtime, but as of 4.3.0 (or perhaps the late 4.2.* series) next no longer works in this way, and this would cause an infinite loop to occur. Instead, use '+1 week': in the above example, the last line inside the loop should be: $prevtime = strtotime('+1 week',$prevtime); Just though I'd leave a note here if anyone else comes with the same problem! ---- Manual Page -- http://www.php.net/manual/en/function.strtotime.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+57714 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57714&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57714&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57714&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57714&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57714&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57714&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57714&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+57714&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#96879) next »