php-general Digest 5 Apr 2011 14:08:45 -0000 Issue 7259

Topics (messages 312265 through 312272):

Re: Please help with glob
        312265 by: Louis Huppenbauer
        312266 by: Al Mangkok
        312267 by: Al Mangkok

Re: DateTime using DateTimeZone Timestamp problem
        312268 by: Ian
        312269 by: Simon J Welsh
        312270 by: Richard Quadling
        312271 by: Ian

randomly random
        312272 by: Kirk Bailey

Administrivia:

To subscribe to the digest, e-mail:
        [email protected]

To unsubscribe from the digest, e-mail:
        [email protected]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---
Hi there

Since glob is actually a part of the core - Are you absolutely sure
that you're running PHP > 4.3

2011/4/5 Al Mangkok <[email protected]>:
> Hi everyone,
> I am very new to PHP and trying to learn the glob() function. I copied
> the example on php.net :
>
> <?php
> foreach (glob("*.txt") as $filename) {
>    echo "$filename size " . filesize($filename) . "\n";
> }
> ?>
>
> When I ran the script, I got this error message:
> Fatal error: Call to undefined function  glob() in
> /usr/local/apache2/htdocs/hrms/globtest.php on line 2
>
> I am running PHP 5.2.17 on CentOS 4.8 . How do I compile PHP to get
> the glob function in ?
> Please help.
>
>
> --
> al
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
Hi Louis,
Yes, I have read that glob is only available for PHP > 4.3 and I am
using version 5.2.1.7

# /usr/local/bin/php -v
PHP 5.2.17 (cli) (built: Feb 16 2011 15:41:35)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies
    with Zend Optimizer v3.3.9, Copyright (c) 1998-2009, by Zend Technologies




# /usr/local/bin/php globtest.php

Fatal error: Call to undefined function  glob() in
/usr/local/apache2/htdocs/hrms/globtest.php on line 2



I have read somewhere that it could be connected to glibc, not I have
no idea how to fix that. Anyone ?


--
al



On Tue, Apr 5, 2011 at 2:25 PM, Louis Huppenbauer
<[email protected]> wrote:
> Hi there
>
> Since glob is actually a part of the core - Are you absolutely sure
> that you're running PHP > 4.3
>
> 2011/4/5 Al Mangkok <[email protected]>:
>> Hi everyone,
>> I am very new to PHP and trying to learn the glob() function. I copied
>> the example on php.net :
>>
>> <?php
>> foreach (glob("*.txt") as $filename) {
>>    echo "$filename size " . filesize($filename) . "\n";
>> }
>> ?>
>>
>> When I ran the script, I got this error message:
>> Fatal error: Call to undefined function  glob() in
>> /usr/local/apache2/htdocs/hrms/globtest.php on line 2
>>
>> I am running PHP 5.2.17 on CentOS 4.8 . How do I compile PHP to get
>> the glob function in ?
>> Please help.
>>
>>
>> --
>> al
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>

--- End Message ---
--- Begin Message ---
Yesterday I yum installed these:
glibc-common.i386 2.3.4-2.54
glibc.i686 2.3.4-2.54
glibc-headers.i386 2.3.4-2.54
glibc-devel.i386 2.3.4-2.54

And about ten minutes ago I recompiled PHP with identical configure
options as before. And this time the glob function is inside PHP.
Phew.

Hopefully someone else will benefit from this post.


--
al

On Tue, Apr 5, 2011 at 2:49 PM, Al Mangkok <[email protected]> wrote:
> Hi Louis,
> Yes, I have read that glob is only available for PHP > 4.3 and I am
> using version 5.2.1.7
>
> # /usr/local/bin/php -v
> PHP 5.2.17 (cli) (built: Feb 16 2011 15:41:35)
> Copyright (c) 1997-2010 The PHP Group
> Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies
>    with Zend Optimizer v3.3.9, Copyright (c) 1998-2009, by Zend Technologies
>
>
>
>
> # /usr/local/bin/php globtest.php
>
> Fatal error: Call to undefined function  glob() in
> /usr/local/apache2/htdocs/hrms/globtest.php on line 2
>
>
>
> I have read somewhere that it could be connected to glibc, not I have
> no idea how to fix that. Anyone ?
>
>
> --
> al
>
>
>
> On Tue, Apr 5, 2011 at 2:25 PM, Louis Huppenbauer
> <[email protected]> wrote:
>> Hi there
>>
>> Since glob is actually a part of the core - Are you absolutely sure
>> that you're running PHP > 4.3
>>
>> 2011/4/5 Al Mangkok <[email protected]>:
>>> Hi everyone,
>>> I am very new to PHP and trying to learn the glob() function. I copied
>>> the example on php.net :
>>>
>>> <?php
>>> foreach (glob("*.txt") as $filename) {
>>>    echo "$filename size " . filesize($filename) . "\n";
>>> }
>>> ?>
>>>
>>> When I ran the script, I got this error message:
>>> Fatal error: Call to undefined function  glob() in
>>> /usr/local/apache2/htdocs/hrms/globtest.php on line 2
>>>
>>> I am running PHP 5.2.17 on CentOS 4.8 . How do I compile PHP to get
>>> the glob function in ?
>>> Please help.
>>>
>>>
>>> --
>>> al
>>>
>>> --
>>> PHP General Mailing List (http://www.php.net/)
>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>>
>>>
>>
>

--- End Message ---
--- Begin Message ---
On 04/04/2011 18:02, Ashley Sheridan wrote:

<snip>
> 
> What do you mean it only returns the timestamp for the local system? Did
> you want PHP to know what time the visitors are on? PHP won't know about
> that, all you can do is set the timezone for the script based on some
> information you're receiving from a clients machine, otherwise PHP won't
> know, because it's only run on the server and doesn't know about the
> client machines? Is this what you're trying to do, or did I
> misunderstand?
> 
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk

Hi,

I want the code to return the timestamp for the current time in
Singapore.  The format command returns different result if the 'U' for
timestamp is specified.  It also returns the same (wrong) result for
DateTime::getTimestamp() as well.

The clients are booking entry into a place at a specific time, for
example 7am in Singapore on the 12 April. Clients can book right up to
the entry time (if there is space available).  I want to make sure they
are not trying to book in the past.

The booking system is in the UK but clients can book from anywhere.  I
cannot rely on them having the right time on their systems (or being in
the right place). Plus this would mean relying on client supplied data,
which is a no-no ;)

I have previously used a gmt offset, which was good enough as there are
not that many people who book close to the entry time.  But now its time
to improve this and use proper time zone info which can change without
my input.


If no-one can find a problem with my code I will submit it as a bug.

Thanks

Ian
-- 





--- End Message ---
--- Begin Message ---
On 5/04/2011, at 3:35 AM, Ian wrote:

> Hi,
> 
> I have a problem using the php built in classes DateTime and DateTimeZone.
> 
> The idea behind the following code is to return the timestamp for the
> current time in Singapore (or other places).  What it actually returns
> is the timestamp for the local system. Other formatted dates appear to
> return correctly, which is why I am puzzled.
> 
> I am using the latest php 5.3.6 compiled from source on a OpenVZ CentOS
> container. All packages are up to date.
> 
> Am I doing something wrong or is this a bug?
> 
> I can workaround this problem my parsing the correctly formatted date
> using strtotime() but I would like to know what's going on.
> 
> 
> 
> This is the output of the script:
> 
>       Current time in Asia/Singapore is 2011-04-04 23:32:36
>       Timestamp for Asia/Singapore is 1301931156
>       Date created from previous timestamp is 2011-04-04 16:32:36
> 
> The code is :
> 
> <?php
> 
> $timezone="Asia/Singapore";
> 
> # Create Timezone object
> $remote_timezone      = new DateTimeZone($timezone);
> 
> # Create datetime object
> $remote_time          = new DateTime("now" , $remote_timezone);
> 
> # Print the date
> print "Current time in {$timezone} ";
> print "is {$remote_time->format("Y-m-d H:i:s")}<br/>";
> 
> # Print the timestamp
> print "Timestamp for {$timezone} ";
> print "is {$remote_time->format("U")}<br />";
> 
> # Get the timestamp and create a date from it
> $timestamp = (int)$remote_time->format("U");
> 
> # Show the formatted date created from timestamp
> print "Date created from previous timestamp is ";
> print date("Y-m-d H:i:s",$timestamp)."<br/>";
> 
> ?>

May I suggest including the timezone in your date format (O or e)? It may show 
the two date strings to be equivalent.

---
Simon Welsh
Admin of http://simon.geek.nz/

Who said Microsoft never created a bug-free program? The blue screen never, 
ever crashes!

http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e


--- End Message ---
--- Begin Message ---
On 4 April 2011 16:35, Ian <[email protected]> wrote:
> Hi,
>
> I have a problem using the php built in classes DateTime and DateTimeZone.
>
> The idea behind the following code is to return the timestamp for the
> current time in Singapore (or other places).  What it actually returns
> is the timestamp for the local system. Other formatted dates appear to
> return correctly, which is why I am puzzled.
>
> I am using the latest php 5.3.6 compiled from source on a OpenVZ CentOS
> container. All packages are up to date.
>
> Am I doing something wrong or is this a bug?
>
> I can workaround this problem my parsing the correctly formatted date
> using strtotime() but I would like to know what's going on.
>
>
>
> This is the output of the script:
>
>        Current time in Asia/Singapore is 2011-04-04 23:32:36
>        Timestamp for Asia/Singapore is 1301931156
>        Date created from previous timestamp is 2011-04-04 16:32:36
>
> The code is :
>
> <?php
>
> $timezone="Asia/Singapore";
>
> # Create Timezone object
> $remote_timezone        = new DateTimeZone($timezone);
>
> # Create datetime object
> $remote_time            = new DateTime("now" , $remote_timezone);
>
> # Print the date
> print "Current time in {$timezone} ";
> print "is {$remote_time->format("Y-m-d H:i:s")}<br/>";
>
> # Print the timestamp
> print "Timestamp for {$timezone} ";
> print "is {$remote_time->format("U")}<br />";
>
> # Get the timestamp and create a date from it
> $timestamp = (int)$remote_time->format("U");
>
> # Show the formatted date created from timestamp
> print "Date created from previous timestamp is ";
> print date("Y-m-d H:i:s",$timestamp)."<br/>";
>
> ?>

Timestamps (the integer value) do not hold the timezone data.
Internally, the value represents a number of milliseconds from a point
in time.

So saying "timestamp for Asia/Singapore" isn't right. It is just "Timestamp".

The following script (http://pastebin.com/0MQAaYUq) may show you in a
more concrete way ...

<?php
$a_Times = array(
        'now',
        '2011-03-27 00:59:59',
        '2011-03-27 02:00:00',
);

// Create Timezone objects
$a_Timezones = array(
        'Singapore' => new DateTimeZone('Asia/Singapore'),
        'NewYork  ' => new DateTimeZone('America/New_York'),
        'London   ' => new DateTimeZone('Europe/London'),
        'UTC      ' => new DateTimeZone('UTC'),
);

foreach($a_Times as $s_Time) {
        echo 'Time : ', $s_Time, PHP_EOL;

        // Create datetime objects
        $a_DateTimes = array();
        foreach($a_Timezones as $s_Timezone => $tz_Timezone) {
                $a_DateTimes[$s_Timezone] = new DateTime($s_Time , 
$tz_Timezone);
        }
        
        // Print the date
        foreach($a_DateTimes as $s_Timezone => $dt_DateTime) {
                echo
                        'Current time in ', $s_Timezone, ' : ', 
$dt_DateTime->format(DateTime::RSS),
                        '   Offset : ', str_pad($dt_DateTime->getOffset(), 6, ' 
', STR_PAD_LEFT),
                        '   Timestamp : ', ($i_Timestamp = 
$dt_DateTime->getTimestamp()),
                        '   Local : ', date(DateTime::RSS, $i_Timestamp), 
PHP_EOL;
        }
        echo PHP_EOL;
}
?>

outputs (http://pastebin.com/mETSbR7h) ...

Time : now
Current time in Singapore : Tue, 05 Apr 2011 17:56:32 +0800   Offset :
 28800   Timestamp : 1301997392   Local : Tue, 05 Apr 2011 10:56:32
+0100
Current time in NewYork   : Tue, 05 Apr 2011 05:56:32 -0400   Offset :
-14400   Timestamp : 1301997392   Local : Tue, 05 Apr 2011 10:56:32
+0100
Current time in London    : Tue, 05 Apr 2011 10:56:32 +0100   Offset :
  3600   Timestamp : 1301997392   Local : Tue, 05 Apr 2011 10:56:32
+0100
Current time in UTC       : Tue, 05 Apr 2011 09:56:32 +0000   Offset :
     0   Timestamp : 1301997392   Local : Tue, 05 Apr 2011 10:56:32
+0100

Time : 2011-03-27 00:59:59
Current time in Singapore : Sun, 27 Mar 2011 00:59:59 +0800   Offset :
 28800   Timestamp : 1301158799   Local : Sat, 26 Mar 2011 16:59:59
+0000
Current time in NewYork   : Sun, 27 Mar 2011 00:59:59 -0400   Offset :
-14400   Timestamp : 1301201999   Local : Sun, 27 Mar 2011 05:59:59
+0100
Current time in London    : Sun, 27 Mar 2011 00:59:59 +0000   Offset :
     0   Timestamp : 1301187599   Local : Sun, 27 Mar 2011 00:59:59
+0000
Current time in UTC       : Sun, 27 Mar 2011 00:59:59 +0000   Offset :
     0   Timestamp : 1301187599   Local : Sun, 27 Mar 2011 00:59:59
+0000

Time : 2011-03-27 02:00:00
Current time in Singapore : Sun, 27 Mar 2011 02:00:00 +0800   Offset :
 28800   Timestamp : 1301162400   Local : Sat, 26 Mar 2011 18:00:00
+0000
Current time in NewYork   : Sun, 27 Mar 2011 02:00:00 -0400   Offset :
-14400   Timestamp : 1301205600   Local : Sun, 27 Mar 2011 07:00:00
+0100
Current time in London    : Sun, 27 Mar 2011 02:00:00 +0100   Offset :
  3600   Timestamp : 1301187600   Local : Sun, 27 Mar 2011 02:00:00
+0100
Current time in UTC       : Sun, 27 Mar 2011 02:00:00 +0000   Offset :
     0   Timestamp : 1301191200   Local : Sun, 27 Mar 2011 03:00:00
+0100


Getting the the timestamp for a DateTime object will return the
timestamp appropriately converted to the local timezone.

If you don't want to lose the timezone, then don't use the timestamp.

This, of course, is an issue if you want to use datetimes in a DB.

In these instances, converting the datetime to UTC and storing the
timezone separately is certainly one option.

If you are using SQL Server 2008, then there is a column type of
DATETIMEOFFSET which is a datetime column with Timezone and
100nanosecond accuracy, so you can store and use datetimes like ...

2007-05-08 12:35:29.1234567 +12:15

Which is a pretty accurate.

I guess there is some difference in logic between knowing the timezone
and the timezone offset.

I found the talk by Derick Rethans very useful : (looking for this but
can't find it any more. The link to it is
http://www.phparch.com/2009/08/dont-miss-todays-webcast-on-date-manipulation/

A book is also available :
http://www.phparch.com/books/phparchitects-guide-to-date-and-time-programming/

I

-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

--- End Message ---
--- Begin Message ---
On 05/04/2011 10:11, Simon J Welsh wrote:
> On 5/04/2011, at 3:35 AM, Ian wrote:
> 
>> Hi,
>>
>> I have a problem using the php built in classes DateTime and DateTimeZone.
>>
>> The idea behind the following code is to return the timestamp for the
>> current time in Singapore (or other places).  What it actually returns
>> is the timestamp for the local system. Other formatted dates appear to
>> return correctly, which is why I am puzzled.
>>
>> I am using the latest php 5.3.6 compiled from source on a OpenVZ CentOS
>> container. All packages are up to date.
>>
>> Am I doing something wrong or is this a bug?
>>
>> I can workaround this problem my parsing the correctly formatted date
>> using strtotime() but I would like to know what's going on.
>>
>>
>>
>> This is the output of the script:
>>
>>      Current time in Asia/Singapore is 2011-04-04 23:32:36
>>      Timestamp for Asia/Singapore is 1301931156
>>      Date created from previous timestamp is 2011-04-04 16:32:36
>>
>> The code is :
>>
>> <?php
>>
>> $timezone="Asia/Singapore";
>>
>> # Create Timezone object
>> $remote_timezone     = new DateTimeZone($timezone);
>>
>> # Create datetime object
>> $remote_time                 = new DateTime("now" , $remote_timezone);
>>
>> # Print the date
>> print "Current time in {$timezone} ";
>> print "is {$remote_time->format("Y-m-d H:i:s")}<br/>";
>>
>> # Print the timestamp
>> print "Timestamp for {$timezone} ";
>> print "is {$remote_time->format("U")}<br />";
>>
>> # Get the timestamp and create a date from it
>> $timestamp = (int)$remote_time->format("U");
>>
>> # Show the formatted date created from timestamp
>> print "Date created from previous timestamp is ";
>> print date("Y-m-d H:i:s",$timestamp)."<br/>";
>>
>> ?>
> 
> May I suggest including the timezone in your date format (O or e)? It may 
> show the two date strings to be equivalent.
> 

Hi,

Found the problem:


Unix timestamps are a moment in time and so timezones have no influences
on them. They count the number of seconds since 1970-01-01 00:00 *UTC*

See: http://en.wikipedia.org/wiki/Unix_time


So the timestamp will always be the same no matter which timezone.
I will use by workaround to get the expected timestamp for use in
comparisons.

Regards

Ian
-- 




--- End Message ---
--- Begin Message --- OK gang, to spew a single line from a file of fortune cookies, I want to read it and echo one line. While I found a 4 line code which gets it done, I thought there was a preexisting command to do exactly that. Any feedback on this?

--
end

Very Truly yours,
                 - Kirk Bailey,
                   Largo Florida

                       kniht
                      +-----+
                      | BOX |
                      +-----+
                       think


--- End Message ---

Reply via email to