note 57714 deleted from function.strtotime by derick

From: Date: Sun, 15 Jul 2007 12:45:26 +0000
Subject: note 57714 deleted from function.strtotime by derick
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-128570@lists.php.net to get a copy of this message
Note Submitter: Leftward Shift, My Wayward Carry ---- 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!

« previous php.notes (#128570) next »