PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.php > Slow performance using strtotime on prior 1970 dates
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Slow performance using strtotime on prior 1970 dates

Réponse
 
LinkBack Outils de la discussion
Vieux 14/09/2007, 20h22   #1 (permalink)
cla
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Slow performance using strtotime on prior 1970 dates

I'm using this code on an application to track football schedules:
----
$season = '2005';
$basedate = strtotime('this friday', strtotime('31 August '.$season));

for($d=0;$d<=31;$d++) {
$d2=strtotime("+".$d." day",$basedate);
echo(date('m d Y',$d2)."\n");
}
----
The purpose is to find the first Friday on or after Aug. 31 in a given
year. Plug '2005' into $season, and it flies through. Plug in
'1905', however, and each step in the for loop takes about .5 sec.
I'm running this code in PHP 5.2.1. Any ideas?

  Réponse avec citation
Vieux 14/09/2007, 20h24   #2 (permalink)
RageARC
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Slow performance using strtotime on prior 1970 dates

Well the fact is 1970 was when the Unix Epoch started, so any dates
prior to that date are much more slower. I don't know why, but try on
a Windows machine and see if the same happens. Probably it's just on
*nix systems.

  Réponse avec citation
Vieux 14/09/2007, 20h59   #3 (permalink)
ZeldorBlat
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Slow performance using strtotime on prior 1970 dates

On Sep 14, 3:22 pm, cla <cla...@gmail.com> wrote:
> I'm using this code on an application to track football schedules:
> ----
> $season = '2005';
> $basedate = strtotime('this friday', strtotime('31 August '.$season));
>
> for($d=0;$d<=31;$d++) {
> $d2=strtotime("+".$d." day",$basedate);
> echo(date('m d Y',$d2)."\n");}
>
> ----
> The purpose is to find the first Friday on or after Aug. 31 in a given
> year. Plug '2005' into $season, and it flies through. Plug in
> '1905', however, and each step in the for loop takes about .5 sec.
> I'm running this code in PHP 5.2.1. Any ideas?


If all you want to do is find the first Friday on or after August 31
why do you need the loop?

  Réponse avec citation
Vieux 14/09/2007, 21h06   #4 (permalink)
cla
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Slow performance using strtotime on prior 1970 dates

On Sep 14, 12:59 pm, ZeldorBlat <zeldorb...@gmail.com> wrote:
> On Sep 14, 3:22 pm, cla <cla...@gmail.com> wrote:
>
> > I'm using this code on an application to track football schedules:
> > ----
> > $season = '2005';
> > $basedate = strtotime('this friday', strtotime('31 August '.$season));

>
> > for($d=0;$d<=31;$d++) {
> > $d2=strtotime("+".$d." day",$basedate);
> > echo(date('m d Y',$d2)."\n");}

>
> > ----
> > The purpose is to find the first Friday on or after Aug. 31 in a given
> > year. Plug '2005' into $season, and it flies through. Plug in
> > '1905', however, and each step in the for loop takes about .5 sec.
> > I'm running this code in PHP 5.2.1. Any ideas?

>
> If all you want to do is find the first Friday on or after August 31
> why do you need the loop?


The loop's more for a demo. In the live app, there's a drop down list
of possible dates within a given week of a season. The first Friday
is just the starting point from which all subsequent dates are
referenced.

  Réponse avec citation
Vieux 14/09/2007, 21h08   #5 (permalink)
cla
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Slow performance using strtotime on prior 1970 dates

On Sep 14, 12:24 pm, RageARC <rage...@gmail.com> wrote:
> Well the fact is 1970 was when the Unix Epoch started, so any dates
> prior to that date are much more slower. I don't know why, but try on
> a Windows machine and see if the same happens. Probably it's just on
> *nix systems.


Made a quick test on a Windows box, and the performance seems to be
about the same.

  Réponse avec citation
Vieux 14/09/2007, 22h08   #6 (permalink)
RageARC
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Slow performance using strtotime on prior 1970 dates

Well, I searched, and I found the following:

The valid range of a timestamp is typically from Fri, 13 Dec 1901
20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT. (These are the dates
that correspond to the minimum and maximum values for a 32-bit signed
integer.) Additionally, not all platforms support negative timestamps,
therefore your date range may be limited to no earlier than the Unix
epoch. This means that e.g. dates prior to Jan 1, 1970 will not work
on Windows, some Linux distributions, and a few other operating
systems. PHP 5.1.0 and newer versions overcome this limitation though.

Yep, 5.1.0 overcomes this limitation, but at a much slower pace.

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 02h57.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,09632 seconds with 14 queries