php-general Digest 17 Oct 2012 02:10:07 -0000 Issue 8010

Topics (messages 319476 through 319496):

Re: foreach
        319476 by: Steven Staples
        319477 by: Samuel Lopes Grigolato
        319478 by: Matijn Woudt
        319479 by: Steven Staples
        319480 by: Ashley Sheridan
        319481 by: Jim Giner
        319488 by: David McGlone
        319489 by: David McGlone
        319495 by: Larry Garfield
        319496 by: tamouse mailing lists

Re: Serving an image
        319482 by: Alan Hoffmeister

Wrong time being displayed by PHP!
        319483 by: Richard S. Crawford
        319484 by: Daniel P. Brown
        319485 by: David OBrien
        319486 by: Adam Richardson
        319487 by: Richard S. Crawford
        319490 by: Enrico Lamperti
        319491 by: Richard S. Crawford
        319492 by: Daniel Brown
        319493 by: Richard S. Crawford
        319494 by: Daniel Brown

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
> Here's what I ended up with after you gave me the advise:
> $result = mysql_query("SELECT * FROM items");
>   $rows = array();
>   while($row = mysql_fetch_array($result))
>    $rows[] = $row;
>   foreach($rows as $row){
>   $product = $row['product'];
>   $price = $row['price'];
>     echo "$product ";
>     echo "$price ";
> 
> 
>     $justright = 0;
>     $toohigh = 5; //I was going to use this to check if the price was too
> high
>                               just so I could use an elseif in the
exercise, but
> I realized that
>                               it would only work if the if() evaluated to
false,
> which would be
>                               impossible. Ahhh pizz on it, it was fun
anyway! :-
> )
> 
>     if($justright <= $price){
>      echo "Not bad. I'll buy it.<br />";
>       } else
>      echo "Too expensive I'm going home LOL ";
> 
>   }
> 
> It's a dumb script that makes no sense but I had a blast doing this. When
> things start coming together like this, it gets so gratifying. :-)
> 
>  --
> David M.


David, 

Just putting this out there, but the use of a foreach() loop here, is
redundant...
You are putting your query results into an array, and then looping through
them after with the foreach(), instead of just using the while loop to loop
through them initially... so you're doing the same thing, twice, just using
the foreach() after the while.

One thing I was always told when I was learning c++ (my teacher was anal,
and always forced us to try and be more efficient), using >= uses more cpu
cycles, than > or <, so when you're checking 0 <= 0.1 true, false, you could
exchange your check to be 0 > 0.1 false, else true...

Also, setting the variable $product and $price, with the value from the
database $row['product'], would be less cycles than to just echo the
$row['product']...

That is just some $0.02...  I wouldn't personally create more code, just to
"try" something out... use the right function for the job, write less code
than needed (sometimes, a little more code for readability is better
though), and most importantly... have fun.

One thing I do, is my coding and bracing style is something that Tedd
Sperling doesn't like (there have been many discussions about bracing
styles),  I keep my braces all in line, and always use them in my if()s...
ie:
        If($yourmom == $hot)
        {
                Echo "MILF!";
        }
        Else
        {
                Echo "Pass.";
        }

And I do this for readability, so I can see if I forgot a brace somewhere,
and also, I always know that there are braces (with a 4space indentation, or
tab stops set at 4 space)

1 more point, doing multiline comments, use /*  insert comment here */  and
not just //, and with that, I use inline comments with #,  but that is just
me.

Overall though, I am glad to see you're learning, and having fun doing so...


Steve Staples.


--- End Message ---
--- Begin Message ---
There is some cases that more code (and more cycles) is a good thing. For
example, a multi-layer architecture (like presentation, business and data
access) is more cpu-intensive than a single page doing everything in an
entangled procedural style, but is far more easy to evolve!

As Steven said, you need to use the right tool for the job. If you're going
to write some cryptographic API for mission-critical applications, or a
network protocol for games with extreme bandwidth demands, every ">="
matters, otherwise, better to stick with readability and separation of
concerns.

Cheers,
Samuel.

-----Mensagem original-----
De: Steven Staples [mailto:sstap...@mnsi.net] 
Enviada em: terça-feira, 16 de outubro de 2012 10:46
Para: 'David McGlone'; 'Bastien'; 'PHP-GENERAL'
Assunto: RE: [PHP] foreach

> Here's what I ended up with after you gave me the advise:
> $result = mysql_query("SELECT * FROM items");
>   $rows = array();
>   while($row = mysql_fetch_array($result))
>    $rows[] = $row;
>   foreach($rows as $row){
>   $product = $row['product'];
>   $price = $row['price'];
>     echo "$product ";
>     echo "$price ";
> 
> 
>     $justright = 0;
>     $toohigh = 5; //I was going to use this to check if the price was 
> too high
>                               just so I could use an elseif in the
exercise, but
> I realized that
>                               it would only work if the if() evaluated to
false,
> which would be
>                               impossible. Ahhh pizz on it, it was fun
anyway! :-
> )
> 
>     if($justright <= $price){
>      echo "Not bad. I'll buy it.<br />";
>       } else
>      echo "Too expensive I'm going home LOL ";
> 
>   }
> 
> It's a dumb script that makes no sense but I had a blast doing this. 
> When things start coming together like this, it gets so gratifying. 
> :-)
> 
>  --
> David M.


David, 

Just putting this out there, but the use of a foreach() loop here, is
redundant...
You are putting your query results into an array, and then looping through
them after with the foreach(), instead of just using the while loop to loop
through them initially... so you're doing the same thing, twice, just using
the foreach() after the while.

One thing I was always told when I was learning c++ (my teacher was anal,
and always forced us to try and be more efficient), using >= uses more cpu
cycles, than > or <, so when you're checking 0 <= 0.1 true, false, you could
exchange your check to be 0 > 0.1 false, else true...

Also, setting the variable $product and $price, with the value from the
database $row['product'], would be less cycles than to just echo the
$row['product']...

That is just some $0.02...  I wouldn't personally create more code, just to
"try" something out... use the right function for the job, write less code
than needed (sometimes, a little more code for readability is better
though), and most importantly... have fun.

One thing I do, is my coding and bracing style is something that Tedd
Sperling doesn't like (there have been many discussions about bracing
styles),  I keep my braces all in line, and always use them in my if()s...
ie:
        If($yourmom == $hot)
        {
                Echo "MILF!";
        }
        Else
        {
                Echo "Pass.";
        }

And I do this for readability, so I can see if I forgot a brace somewhere,
and also, I always know that there are braces (with a 4space indentation, or
tab stops set at 4 space)

1 more point, doing multiline comments, use /*  insert comment here */  and
not just //, and with that, I use inline comments with #,  but that is just
me.

Overall though, I am glad to see you're learning, and having fun doing so...


Steve Staples.


--
PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
http://www.php.net/unsub.php



--- End Message ---
--- Begin Message ---
On Tue, Oct 16, 2012 at 3:46 PM, Steven Staples <sstap...@mnsi.net> wrote:
> One thing I do, is my coding and bracing style is something that Tedd
> Sperling doesn't like (there have been many discussions about bracing
> styles),  I keep my braces all in line, and always use them in my if()s...
> ie:
<snip violent language>
>
> And I do this for readability, so I can see if I forgot a brace somewhere,
> and also, I always know that there are braces (with a 4space indentation, or
> tab stops set at 4 space)
>
>
> Steve Staples.


Steve,

Please watch your language on this list.

- Matijn

--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: Matijn Woudt [mailto:tijn...@gmail.com]
> Steve,
> 
> Please watch your language on this list.
> 
> - Matijn
> 

My apologies, I guess using $foo == $bar would have been a better choice... I 
forget sometimes, I am used to chatting with my close friends, where stuff like 
that is pretty tame.

I meant no disrespect to anyone.

Steve Staples.


--- End Message ---
--- Begin Message ---
On Tue, 2012-10-16 at 10:11 -0400, Steven Staples wrote:

> > -----Original Message-----
> > From: Matijn Woudt [mailto:tijn...@gmail.com]
> > Steve,
> > 
> > Please watch your language on this list.
> > 
> > - Matijn
> > 
> 
> My apologies, I guess using $foo == $bar would have been a better choice... I 
> forget sometimes, I am used to chatting with my close friends, where stuff 
> like that is pretty tame.
> 
> I meant no disrespect to anyone.
> 
> Steve Staples.
> 
> 


I wouldn't have said the language was violent, maybe just a tad too
'Friday', but hey.

I also prefer my braces lined up like that. Sure it results in a few
more lines, but it sure makes more sense when I'm going over old code.

-- 
Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
On 10/15/2012 8:39 PM, Jim Lucas wrote:
On 10/15/2012 05:16 PM, David McGlone wrote:
I've been sitting here playing around with foreach() and I'm wondering
why I
am getting these results. here's what I've been fooling around with.
the code
has no perticular meaning, but I noticed if the script fails, I get the
sentence "Too expensive I'm going home LOL" 6 times because there are
6 words
in the sentence. I also have a database that looks like this:

product_id        product        price
1                Milk        2.59
2                bread        1.05

And when $row is equal to 0 the output I get is
1 1 Milk Milk 2.59 2.59 Which is printed to the screen according to
how many
rows are in the db I belive.

So my question is why this behavior? I was expecting something like a
while
loop.


Code please.

You want code?  IF it's anything like what he showed already, who cares?

--- End Message ---
--- Begin Message ---
On Tuesday, October 16, 2012 09:46:26 AM you wrote:
> > Here's what I ended up with after you gave me the advise:
> > $result = mysql_query("SELECT * FROM items");
> > 
> >   $rows = array();
> >   while($row = mysql_fetch_array($result))
> >   
> >    $rows[] = $row;
> >   
> >   foreach($rows as $row){
> >   $product = $row['product'];
> >   $price = $row['price'];
> >   
> >     echo "$product ";
> >     echo "$price ";
> >     
> >     
> >     $justright = 0;
> >     $toohigh = 5; //I was going to use this to check if the price was too
> > 
> > high
> > 
> >                             just so I could use an elseif in the
> 
> exercise, but
> 
> > I realized that
> > 
> >                             it would only work if the if() evaluated to
> 
> false,
> 
> > which would be
> > 
> >                             impossible. Ahhh pizz on it, it was fun
> 
> anyway! :-
> 
> > )
> > 
> >     if($justright <= $price){
> >     
> >      echo "Not bad. I'll buy it.<br />";
> >      
> >       } else
> >      
> >      echo "Too expensive I'm going home LOL ";
> >   
> >   }
> > 
> > It's a dumb script that makes no sense but I had a blast doing this. When
> > things start coming together like this, it gets so gratifying. :-)
> > 
> >  --
> > 
> > David M.
> 
> David,
> 
> Just putting this out there, but the use of a foreach() loop here, is
> redundant...
> You are putting your query results into an array, and then looping through
> them after with the foreach(), instead of just using the while loop to loop
> through them initially... so you're doing the same thing, twice, just using
> the foreach() after the while.
> 
> One thing I was always told when I was learning c++ (my teacher was anal,
> and always forced us to try and be more efficient), using >= uses more cpu
> cycles, than > or <, so when you're checking 0 <= 0.1 true, false, you could
> exchange your check to be 0 > 0.1 false, else true...

This is what I like to hear. It's stuff like this this that I haven't found in 
a text book. Even when Bastian said "$row is a pointer....." Ah Yes! That 
helped tremendously.

> 
> Also, setting the variable $product and $price, with the value from the
> database $row['product'], would be less cycles than to just echo the
> $row['product']...

Hehehehe who said I wanted this exercise to be easy? LMBO
> 
> That is just some $0.02...  I wouldn't personally create more code, just to
> "try" something out... use the right function for the job, write less code
> than needed (sometimes, a little more code for readability is better
> though), and most importantly... have fun.

I appreciate your feedback and it's conversations like this that help the 
most.
> 
> One thing I do, is my coding and bracing style is something that Tedd
> Sperling doesn't like (there have been many discussions about bracing
> styles),  I keep my braces all in line, and always use them in my if()s...
> ie:
>       If($yourmom == $hot)
>       {
>               Echo "MILF!";
>       }
>       Else
>       {
>               Echo "Pass.";
>       }
> 
> And I do this for readability, so I can see if I forgot a brace somewhere,
> and also, I always know that there are braces (with a 4space indentation, or
> tab stops set at 4 space)

I have Kate set up to create auto brackets so I'll never forget to close one 
and I have lines on the left hand side that connect each open bracket to it's 
corresponding close bracket. Any open end lines means I'm missing something.
> 
> 1 more point, doing multiline comments, use /*  insert comment here */  and
> not just //, and with that, I use inline comments with #,  but that is just
> me.

That long comment I made about the variable I didn't use was actually typed in 
the e-mail in my reply to Bastian and wasn't in the code. If it was in the 
code I would have used /* */
> 
> Overall though, I am glad to see you're learning, and having fun doing so...

Thanks. The whole purpose of me doing this was to get to play with foreach() 
and I've been down with while for a while.. LMBO it was just too easy to use 
while and I was trying to force myself to keep thinking.

When Bastian pointed out that $row was a pointer, just that little bit of info 
changed the whole course of how I was thinking. I was thinking $row was an 
array with all the results in it and with his little bit of info and knowing I 
wanted to play around with foreach() I just stuck to whatever came up and this 
is what the result was... :-)

Alot of times I need to be reminded. Like hey! that's a CONSTANT not a 
$variable!!

-- 
David M.


--- End Message ---
--- Begin Message ---
On Tuesday, October 16, 2012 11:02:18 AM Samuel Lopes Grigolato wrote:
> There is some cases that more code (and more cycles) is a good thing. For
> example, a multi-layer architecture (like presentation, business and data
> access) is more cpu-intensive than a single page doing everything in an
> entangled procedural style, but is far more easy to evolve!
> 
> As Steven said, you need to use the right tool for the job. If you're going
> to write some cryptographic API for mission-critical applications, or a
> network protocol for games with extreme bandwidth demands, every ">="
> matters, otherwise, better to stick with readability and separation of
> concerns.
> 
> Cheers,
> Samuel.
> 
> -----Mensagem original-----
> De: Steven Staples [mailto:sstap...@mnsi.net]
> Enviada em: terça-feira, 16 de outubro de 2012 10:46
> Para: 'David McGlone'; 'Bastien'; 'PHP-GENERAL'
> Assunto: RE: [PHP] foreach
> 
> > Here's what I ended up with after you gave me the advise:
> > $result = mysql_query("SELECT * FROM items");
> > 
> >   $rows = array();
> >   while($row = mysql_fetch_array($result))
> >   
> >    $rows[] = $row;
> >   
> >   foreach($rows as $row){
> >   $product = $row['product'];
> >   $price = $row['price'];
> >   
> >     echo "$product ";
> >     echo "$price ";
> >     
> >     
> >     $justright = 0;
> >     $toohigh = 5; //I was going to use this to check if the price was
> > 
> > too high
> > 
> >                             just so I could use an elseif in the
> 
> exercise, but
> 
> > I realized that
> > 
> >                             it would only work if the if() evaluated to
> 
> false,
> 
> > which would be
> > 
> >                             impossible. Ahhh pizz on it, it was fun
> 
> anyway! :-
> 
> > )
> > 
> >     if($justright <= $price){
> >     
> >      echo "Not bad. I'll buy it.<br />";
> >      
> >       } else
> >      
> >      echo "Too expensive I'm going home LOL ";
> >   
> >   }
> > 
> > It's a dumb script that makes no sense but I had a blast doing this.
> > When things start coming together like this, it gets so gratifying.
> > 
> > :-)
> > :
> >  --
> > 
> > David M.
> 
> David,
> 
> Just putting this out there, but the use of a foreach() loop here, is
> redundant...
> You are putting your query results into an array, and then looping through
> them after with the foreach(), instead of just using the while loop to loop
> through them initially... so you're doing the same thing, twice, just using
> the foreach() after the while.
> 
> One thing I was always told when I was learning c++ (my teacher was anal,
> and always forced us to try and be more efficient), using >= uses more cpu
> cycles, than > or <, so when you're checking 0 <= 0.1 true, false, you could
> exchange your check to be 0 > 0.1 false, else true...
> 
> Also, setting the variable $product and $price, with the value from the
> database $row['product'], would be less cycles than to just echo the
> $row['product']...
> 
> That is just some $0.02...  I wouldn't personally create more code, just to
> "try" something out... use the right function for the job, write less code
> than needed (sometimes, a little more code for readability is better
> though), and most importantly... have fun.
> 
> One thing I do, is my coding and bracing style is something that Tedd
> Sperling doesn't like (there have been many discussions about bracing
> styles),  I keep my braces all in line, and always use them in my if()s...
> ie:
>       If($yourmom == $hot)
>       {
>               Echo "MILF!";
>       }
>       Else
>       {
>               Echo "Pass.";
>       }
> 
> And I do this for readability, so I can see if I forgot a brace somewhere,
> and also, I always know that there are braces (with a 4space indentation, or
> tab stops set at 4 space)
> 
> 1 more point, doing multiline comments, use /*  insert comment here */  and
> not just //, and with that, I use inline comments with #,  but that is just
> me.
> 
> Overall though, I am glad to see you're learning, and having fun doing so...

+1 Great advise from both of you and very appreciated.
-- 
David M.


--- End Message ---
--- Begin Message ---
On 10/15/12 9:05 PM, David McGlone wrote:
On Monday, October 15, 2012 08:21:23 PM you wrote:
Bastien Koert

On 2012-10-15, at 8:16 PM, David McGlone <da...@dmcentral.net> wrote:
I've been sitting here playing around with foreach() and I'm wondering why
I am getting these results. here's what I've been fooling around with.
the code has no perticular meaning, but I noticed if the script fails, I
get the sentence "Too expensive I'm going home LOL" 6 times because there
are 6 words in the sentence. I also have a database that looks like this:

product_id        product        price
1                Milk        2.59
2                bread        1.05

And when $row is equal to 0 the output I get is
1 1 Milk Milk 2.59 2.59 Which is printed to the screen according to how
many rows are in the db I belive.

So my question is why this behavior? I was expecting something like a
while
loop.

Dave,

Foreach is an iterator over an array. Your $row is a pointer to a db result
set. If you were to pass the $row result set to the foreach as an array,
you'd get what you think you should

Www.php.net/foreach

Thanks Bastien.
Heres what I started with:

$result = mysql_query("SELECT * FROM items");
$row = mysql_fetch_array($result);
foreach($row as $rows){
$row = 0;
if($row == 0){
echo $rows;
} else{
echo "Too expensive I'm going home LOL";
}
}

Here's what I ended up with after you gave me the advise:
$result = mysql_query("SELECT * FROM items");
   $rows = array();
   while($row = mysql_fetch_array($result))
    $rows[] = $row;
   foreach($rows as $row){
   $product = $row['product'];
   $price = $row['price'];
     echo "$product ";
     echo "$price ";


     $justright = 0;
     $toohigh = 5; //I was going to use this to check if the price was too high
                                just so I could use an elseif in the exercise, 
but I realized that
                                it would only work if the if() evaluated to 
false, which would be       
                                impossible. Ahhh pizz on it, it was fun anyway! 
:-)

     if($justright <= $price){
      echo "Not bad. I'll buy it.<br />";
       } else
      echo "Too expensive I'm going home LOL ";

   }

For the love of god, please stop using ext/mysql (aka the mysql_* functions). It's insecure and slow and lacks features.

Instead, use PDO, and bind your parameters. As a nice bonus, the result from a PDO-based query is not a raw resource but an iteratable object, which means you can foreach() it.

http://php.net/manual/en/book.pdo.php

$conn = new PDO(...);
$result = $conn->query("SELECT * FROM items");
foreach ($result as $record) {
  // Do something with each record here.
}

--Larry Garfield

--- End Message ---
--- Begin Message ---
On Tue, Oct 16, 2012 at 6:25 PM, Larry Garfield <la...@garfieldtech.com> wrote:
> Instead, use PDO, and bind your parameters.  As a nice bonus, the result
> from a PDO-based query is not a raw resource but an iteratable object, which
> means you can foreach() it.
>
> http://php.net/manual/en/book.pdo.php
>
> $conn = new PDO(...);
> $result = $conn->query("SELECT * FROM items");
> foreach ($result as $record) {
>   // Do something with each record here.
> }
>
> --Larry Garfield

Bonus round:

Remember if you do multiple queries to also issue the close when you
are done with the current result set:

$result->closeCursor();

(not all dbms drivers have this limitation, but defensive coding is defensive.)

--- End Message ---
--- Begin Message ---
2012/10/15 viper <recursivepoin...@gmail.com>:
> On Mon, Oct 15, 2012 at 5:48 PM, Rick Dwyer <rpdw...@earthlink.net> wrote:
>> I am sending an email with a logo at the top of the email.  The source of 
>> the image for the logo is:
>>
>> http://myurl.com/image.php?id=5
>>
>> Image.php then calls a function that simply returns the following:
>>
>>
>>
>> $image='<img src="http://myurl.com/images/logo.jpg"; />';
>> return $image;
>>
>>
>>
>> Calling the page directly via the URL http://myurl.com/image.php?id=5 works 
>> fine.
>> But when the email is opened, I get the broken link/image icon even though I 
>> can see in my source that the URL which works when loaded into a browser.
>>
>> What needs to be done to serve that image to a email client when it is 
>> opened?
>
> in image.php you should return an image/xxx file and not an HTML tag.
> try something like this:
>
> image.php:
>
> $im = imagecreatefrompng("test.png");
> header('Content-Type: image/png');
> imagepng($im);
> imagedestroy($im);
>
> then in your email you can put:
> <img src="http://myurl.com/image.php?id=5"; />
>

What is the diference between using imagecreatefrompng() and readfile()?
Any performance improvement?

--- End Message ---
--- Begin Message ---
The value of date.timezone in php.ini is set to "America/Los_Angeles".

The local time is 11:02 a.m. Yet the output of date("h:i a e") is:

02:02 pm America/Los_Angeles

which is three hours ahead of the real time.

Why is this? What's going on?

-- 
Sláinte,
Richard S. Crawford (rich...@underpope.com) http://www.underpope.com
Twitter: http://twitter.com/underpope
Facebook: http://www.facebook.com/underpope
Google+: http://gplus.to/underpope

--- End Message ---
--- Begin Message ---
On Tue, Oct 16, 2012 at 2:02 PM, Richard S. Crawford
<rich...@underpope.com> wrote:
> The value of date.timezone in php.ini is set to "America/Los_Angeles".
>
> The local time is 11:02 a.m. Yet the output of date("h:i a e") is:
>
> 02:02 pm America/Los_Angeles
>
> which is three hours ahead of the real time.
>
> Why is this? What's going on?

    Your server time is probably set incorrectly.  That's EDT, not
PDT, so it sounds like the timezone is what you expect, but the system
time is incorrect.

-- 
</Daniel P. Brown>
Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting
(866-) 725-4321
http://www.parasane.net/

--- End Message ---
--- Begin Message ---
On Tue, Oct 16, 2012 at 2:02 PM, Richard S. Crawford
<rich...@underpope.com>wrote:

> The value of date.timezone in php.ini is set to "America/Los_Angeles".
>
> The local time is 11:02 a.m. Yet the output of date("h:i a e") is:
>
> 02:02 pm America/Los_Angeles
>
> which is three hours ahead of the real time.
>
> Why is this? What's going on?
>
> --
> Sláinte,
> Richard S. Crawford (rich...@underpope.com) http://www.underpope.com
> Twitter: http://twitter.com/underpope
> Facebook: http://www.facebook.com/underpope
> Google+: http://gplus.to/underpope
>

the clock on the server is wrong?

--- End Message ---
--- Begin Message ---
On Tue, Oct 16, 2012 at 2:02 PM, Richard S. Crawford
<rich...@underpope.com> wrote:
> The value of date.timezone in php.ini is set to "America/Los_Angeles".
>
> The local time is 11:02 a.m. Yet the output of date("h:i a e") is:
>
> 02:02 pm America/Los_Angeles
>
> which is three hours ahead of the real time.
>
> Why is this? What's going on?

The server's time could be wrong. Or, code somewhere could be
(re)setting the timezone.

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com

--- End Message ---
--- Begin Message ---
I double checked the server time. It is set to "America/Los_Angeles" as
well.


On Tue, Oct 16, 2012 at 11:07 AM, Adam Richardson <simples...@gmail.com>wrote:

> On Tue, Oct 16, 2012 at 2:02 PM, Richard S. Crawford
> <rich...@underpope.com> wrote:
> > The value of date.timezone in php.ini is set to "America/Los_Angeles".
> >
> > The local time is 11:02 a.m. Yet the output of date("h:i a e") is:
> >
> > 02:02 pm America/Los_Angeles
> >
> > which is three hours ahead of the real time.
> >
> > Why is this? What's going on?
>
> The server's time could be wrong. Or, code somewhere could be
> (re)setting the timezone.
>
> Adam
>
> --
> Nephtali:  A simple, flexible, fast, and security-focused PHP framework
> http://nephtaliproject.com
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Sláinte,
Richard S. Crawford (rich...@underpope.com)
http://www.underpope.com
Publisher and Editor in Chief, Daikaijuzine (http://www.daikaijuzine.com)

--- End Message ---
--- Begin Message ---
You could try using
date_default_timezone_set<http://php.net/manual/en/function.date-default-timezone-set.php>()
in your script, instead.

And if you don't need to care about DST, you can define a specific GMT
offset <http://www.php.net/manual/en/timezones.others.php>.

Hope it helps :)

On Tue, Oct 16, 2012 at 3:56 PM, Richard S. Crawford <
rscrawf...@mossroot.com> wrote:

> I double checked the server time. It is set to "America/Los_Angeles" as
> well.
>
>
> On Tue, Oct 16, 2012 at 11:07 AM, Adam Richardson <simples...@gmail.com
> >wrote:
>
> > On Tue, Oct 16, 2012 at 2:02 PM, Richard S. Crawford
> > <rich...@underpope.com> wrote:
> > > The value of date.timezone in php.ini is set to "America/Los_Angeles"..
> > >
> > > The local time is 11:02 a.m. Yet the output of date("h:i a e") is:
> > >
> > > 02:02 pm America/Los_Angeles
> > >
> > > which is three hours ahead of the real time.
> > >
> > > Why is this? What's going on?
> >
> > The server's time could be wrong. Or, code somewhere could be
> > (re)setting the timezone.
> >
> > Adam
> >
> > --
> > Nephtali:  A simple, flexible, fast, and security-focused PHP framework
> > http://nephtaliproject.com
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
>
> --
> Sláinte,
> Richard S. Crawford (rich...@underpope.com)
> http://www.underpope.com
> Publisher and Editor in Chief, Daikaijuzine (http://www.daikaijuzine.com)
>



-- 
Enrico

--- End Message ---
--- Begin Message ---
On Tue, Oct 16, 2012 at 12:42 PM, Enrico Lamperti <z...@irken.com.ar> wrote:

> You could try using
> date_default_timezone_set<
> http://php.net/manual/en/function.date-default-timezone-set.php>()
> in your script, instead.
>
> And if you don't need to care about DST, you can define a specific GMT
> offset <http://www.php.net/manual/en/timezones.others.php>.
>
> Hope it helps :)
>
>
Hi Enrico,

Thanks for the suggestion. Unfortunately the problem seems to be that PHP
thinks the America/Los_Angeles timezone is the same as EDT. I'm not sure
how to approach this issue.

Richard



> On Tue, Oct 16, 2012 at 3:56 PM, Richard S. Crawford <
> rscrawf...@mossroot.com> wrote:
>
> > I double checked the server time. It is set to "America/Los_Angeles" as
> > well.
> >
> >
> > On Tue, Oct 16, 2012 at 11:07 AM, Adam Richardson <simples...@gmail.com
> > >wrote:
> >
> > > On Tue, Oct 16, 2012 at 2:02 PM, Richard S. Crawford
> > > <rich...@underpope.com> wrote:
> > > > The value of date.timezone in php.ini is set to
> "America/Los_Angeles"..
> > > >
> > > > The local time is 11:02 a.m. Yet the output of date("h:i a e") is:
> > > >
> > > > 02:02 pm America/Los_Angeles
> > > >
> > > > which is three hours ahead of the real time.
> > > >
> > > > Why is this? What's going on?
> > >
> > > The server's time could be wrong. Or, code somewhere could be
> > > (re)setting the timezone.
> > >
> > > Adam
> > >
> > > --
> > > Nephtali:  A simple, flexible, fast, and security-focused PHP framework
> > > http://nephtaliproject.com
> > >
> > > --
> > > PHP General Mailing List (http://www.php.net/)
> > > To unsubscribe, visit: http://www.php.net/unsub.php
> > >
> > >
> >
> >
> > --
> > Sláinte,
> > Richard S. Crawford (rich...@underpope.com)
> > http://www.underpope.com
> > Publisher and Editor in Chief, Daikaijuzine (http://www.daikaijuzine.com
> )
> >
>
>
>
> --
> Enrico
>



-- 
Sláinte,
Richard S. Crawford (rich...@underpope.com)
http://www.underpope.com
Publisher and Editor in Chief, Daikaijuzine (http://www.daikaijuzine.com)

--- End Message ---
--- Begin Message ---
On Tue, Oct 16, 2012 at 4:19 PM, Richard S. Crawford
<rscrawf...@mossroot.com> wrote:
>
> Thanks for the suggestion. Unfortunately the problem seems to be that PHP
> thinks the America/Los_Angeles timezone is the same as EDT. I'm not sure
> how to approach this issue.

    Per list rules, just a gentle reminder: please don't top-post.

    With regard to debugging your issue, it's extremely unlikely that
it's PHP's fault, since no one else has the same issue.  However, it
does indeed sound as though there's a configuration mismatch or a bad
setting of the system clock (as suggested earlier by myself and
others).  What's the output when you run the code below?

<?php

if (php_sapi_name() == 'cli') {
        define('NL',PHP_EOL);
} else {
        define('NL','<br/>'.PHP_EOL);
}

echo date_default_timezone_get().NL;

echo date('r').NL;

echo gmdate('r').NL;

echo time().' ('.date('Z').')'.NL;

echo trim(`date`).NL;

?>

-- 
</Daniel P. Brown>
Network Infrastructure Manager
http://www.php.net/

--- End Message ---
--- Begin Message ---
On Tue, Oct 16, 2012 at 2:05 PM, Daniel Brown <danbr...@php.net> wrote:

> On Tue, Oct 16, 2012 at 4:19 PM, Richard S. Crawford
> <rscrawf...@mossroot.com> wrote:
> >
> > Thanks for the suggestion. Unfortunately the problem seems to be that PHP
> > thinks the America/Los_Angeles timezone is the same as EDT. I'm not sure
> > how to approach this issue.
>
>     Per list rules, just a gentle reminder: please don't top-post.
>

Sorry about that. I was getting very frustrated with the issue, and I
forgot. I'll be sure to keep it in mind.



>     With regard to debugging your issue, it's extremely unlikely that
> it's PHP's fault, since no one else has the same issue.  However, it
> does indeed sound as though there's a configuration mismatch or a bad
> setting of the system clock (as suggested earlier by myself and
> others).  What's the output when you run the code below?
>
> <?php
>
> if (php_sapi_name() == 'cli') {
>         define('NL',PHP_EOL);
> } else {
>         define('NL','<br/>'.PHP_EOL);
> }
>
> echo date_default_timezone_get().NL;
>
> echo date('r').NL;
>
> echo gmdate('r').NL;
>
> echo time().' ('.date('Z').')'.NL;
>
> echo trim(`date`).NL;
>
> ?>
>  <http://www.php.net/unsub.php>
>

This is the output:

America/Los_Angeles
Tue, 16 Oct 2012 17:22:09 -0400
Tue, 16 Oct 2012 21:22:09 +0000
1350422529 (-14400)
Tue Oct 16 17:22:09 EDT 2012





-- 
Sláinte,
Richard S. Crawford (rich...@underpope.com)
http://www.underpope.com
Publisher and Editor in Chief, Daikaijuzine (http://www.daikaijuzine.com)

--- End Message ---
--- Begin Message ---
On Oct 16, 2012 5:24 PM, "Richard S. Crawford" <rscrawf...@mossroot.com>
wrote:
>
> Sorry about that. I was getting very frustrated with the issue, and I
forgot. I'll be sure to keep it in mind.

    No worries.

>>
>>     With regard to debugging your issue, it's extremely unlikely that
>> it's PHP's fault, since no one else has the same issue.  However, it
>> does indeed sound as though there's a configuration mismatch or a bad
>> setting of the system clock (as suggested earlier by myself and
>> others).  What's the output when you run the code below?
>>
>> <?php
>>
>> if (php_sapi_name() == 'cli') {
>>         define('NL',PHP_EOL);
>> } else {
>>         define('NL','<br/>'.PHP_EOL);
>> }
>>
>> echo date_default_timezone_get().NL;
>>
>> echo date('r').NL;
>>
>> echo gmdate('r').NL;
>>
>> echo time().' ('.date('Z').')'.NL;
>>
>> echo trim(`date`).NL;
>>
>> ?>
>
>
> This is the output:
>
> America/Los_Angeles
> Tue, 16 Oct 2012 17:22:09 -0400
> Tue, 16 Oct 2012 21:22:09 +0000
> 1350422529 (-14400)
> Tue Oct 16 17:22:09 EDT 2012

    Is this a shared server, Rich? As shown, the admin configured the
timezone of the machine to be EDT and set the clock right, but php.ini must
be set to PDT. You can easily override this with a local php.ini file, an
.htaccess directive, or by placing date_default_timezone_set() near the top
of the code.

--- End Message ---

Reply via email to