php-general Digest 20 Nov 2011 23:46:17 -0000 Issue 7578

Topics (messages 315773 through 315779):

Re: Sniping on the List
        315773 by: Geoff Shang
        315775 by: Tedd Sperling
        315777 by: Geoff Shang

Re: Parsing the From field
        315774 by: Geoff Shang

Re: include
        315776 by: Tim Streater
        315778 by: shiplu
        315779 by: Tamara Temple

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 ---
On Sat, 19 Nov 2011, Tedd Sperling wrote:

My observations are demonstrated here:

http://www.webbytedd.com/cccc/strtotime/index.php

this code would IMHO be more useful if it also displayed time, not just date. It's also not clear what timezone you're using, as it's not set as far as I can see.

Please note that regardless of time zone, the strtotime() function works (or at least it does for me) such that:

If you enter '-1', the function will report back Todays Date with current seconds. Note there is no difference between entering 'Today' or '-1'.

This is not what your code shows.

String Given: -1

Seconds Computed from String: 1321805103

Date from Seconds Computed: 20 November, 2011 : Sunday

___________________________________________________________________________

Current Time (seconds): 1321819503

Current Date: 20 November, 2011 : Sunday

This is a difference of 14400 seconds or 4 hours.

String Given: today

Seconds Computed from String: 1321765200

Date from Seconds Computed: 20 November, 2011 : Sunday

___________________________________________________________________________

Current Time (seconds): 1321819877

Current Date: 20 November, 2011 : Sunday

This is a much larger difference. 'today' is meant to return the same as 'today 00:00:00'. I know it used not to, it was a PHP bug awhile back... which begs the question, which PHP version are you using?

If you enter '0', the function will report back December, 31, 1969.

You'll also notice that the value of seconds computed from string is blank (i.e. not 0). This is because strtotime() doesn't know what to do with a value of '0'. Whether it should or not is probably a phillosophical debate.

If you enter nothing (i.e., null), then it reports back December, 31, 1969.

It does, but we dont' know exactly when this is because your script doesn't show time. It could be actually returning a 0 timestamp.

We can force your script to show us what 0 time is according to its timezone by entering an absolute date including UTC offset.

String Given: 1 January 1970 +0000

Seconds Computed from String: 0

Date from Seconds Computed: 31 December, 1969 : Wednesday

___________________________________________________________________________

So your script shows 31/12/1969 for the epoch, so we dont' know if the null value is the epoch or before.

To further prove my point, witness the number of seconds calculated from 1 January 1970 in your script's timezone:

String Given: 1 January 1970

Seconds Computed from String: 18000

Date from Seconds Computed: 1 January, 1970 : Thursday

___________________________________________________________________________

This means your script is using a timezone of UTC -0500 (US Eastern). So any time within the first 5 hours of the epoch will show as being in 1969.

To avoid this, explicitly set your script to use UTC. Or use US Eastern but be up front about the fact that your'e doing this.

It's clear (and by definition) that unix zero time (i.e., 00:00:00) happened in 
1970.

It's also clear that time before unix zero happened before 1970 (i.e., 
'December 31, 1969').

As such, null (and not the string 'null' as stated my someone else, duh) should come back as 
"undefined" OR "December, 31, 1969".

It doesn't for me, using either PHP 5.2.6 or 5.3.3.

php -r 'echo date ("r", strtotime (""));'
Thu, 01 Jan 1970 00:00:00 +0000

Furthermore, the string '-1' should default to '-1 second' instead of being the 
same as if I entered 'Today'.

Apart from the fact that for me at least, strtotime ("today") returns today at midnight, whereas strtotime ("-1") seems to return something else (time() + 3600 on boxes set to UTC, time() + 10800 on my box set to local time in Israel), strtotime is meant to turn textual representations of time into a unix timestamp. Surely the meaning of "-1" is at the very least ambiguous, and the fact that it returns anything is surprising.

Now, where are my observations wrong? The code is shown in the demo.

To summarise, your observations are wrong because they do not take timezone into account and do not show the time, only the date. And some of your observations as given above do not match what your script outputs.

Geoff.

--- End Message ---
--- Begin Message ---
On Nov 20, 2011, at 4:00 PM, Geoff Shang wrote:
> On Sat, 19 Nov 2011, Tedd Sperling wrote:
> 
>> Now, where are my observations wrong? The code is shown in the demo.
> 
> To summarise, your observations are wrong because they do not take timezone 
> into account and do not show the time, only the date.  And some of your 
> observations as given above do not match what your script outputs.
> 
> Geoff.
> 

Geof:

I appreciate your time and comments. However, you missed the point I was trying 
to make, which does not have anything to do with timezones. If you copy my code 
and place it on any server in the world, you'll observe the same results as I 
did.

You touched on my point with:

> You'll also notice that the value of seconds computed from string is blank 
> (i.e. not 0).  This is because strtotime() doesn't know what to do with a 
> value of '0'.  Whether it should or not is probably a phillosophical debate.

But you did not contribute to which side of the debate would you side.

My prior opinion was that 0 should return 'Jan 1, 1970'. However, Stuart 
pointed out a flaw in my code.  You see, I was assuming that using the return 
from strtotime(0) in the getdate() function would return the correct date, but 
this was a cascade error.

I have not investigated this further.

Cheers,

tedd

_____________________
t...@sperling.com
http://sperling.com



--- End Message ---
--- Begin Message ---
On Sun, 20 Nov 2011, Tedd Sperling wrote:

I appreciate your time and comments. However, you missed the point I was trying to make, which does not have anything to do with timezones. If you copy my code and place it on any server in the world, you'll observe the same results as I did.

NO I won't, and timezones do matter.

I've copied your code to http://quitelikely.com/~geoff/strtotime/

Sorry if any of the visuals are mangled, I had to massage the script a little to pullin the header and footer, and I downloaded your logo, but I didn't go and dig out your CSS or javascript.

This server is set to UTC and uses PHP 5.2.6.

Lets skip right to your point.

From your script on your server:

String Given: null

Seconds Computed from String: null

Date from Seconds Computed: 31 December, 1969 : Wednesday
___________________________________________________________________________

From the script on my server:

   String Given: null

   Seconds Computed from String: null

   Date from Seconds Computed: 1 January, 1970 : Thursday
     __________________________________________________________________

You touched on my point with:

You'll also notice that the value of seconds computed from string is blank (i.e. not 0). This is because strtotime() doesn't know what to do with a value of '0'. Whether it should or not is probably a phillosophical debate.

But you did not contribute to which side of the debate would you side.

I didn't, because the debate was on whether or not NULL == Wednesday, not whether or not strtotime("0") should return 0. I agree there's a good case for it doing so, you could file a bug if you feel strongly about it.

My prior opinion was that 0 should return 'Jan 1, 1970'. However, Stuart pointed out a flaw in my code. You see, I was assuming that using the return from strtotime(0) in the getdate() function would return the correct date, but this was a cascade error.

As I think I mentioned before, using strtotime at all is the problem, as we are talking about null as a concept, not "null" the alphabetical string. Since null is nominally a numerical value, we can pass it directly as a timestamp.

php -r 'echo date("r", null);'
Thu, 01 Jan 1970 00:00:00 +0000

Geoff.

--- End Message ---
--- Begin Message ---
On Sat, 19 Nov 2011, Ron Piggott wrote:

Also the formatting of the from field changes in various e-mail programs:

From: Ron Piggott <ron.pigg...@actsministries.org>
From: "Ron Piggott" <ron.pigg...@actsministries.org>
From: ron.pigg...@actsministries.org
From: <ron.pigg...@actsministries.org>

I've also seen:

Piggott, Ron <ron.pigg...@actsministries.org>

And that's before you get to people who only use their first name and people who use some kind of alias.

I think you did well to abandon this.

Geoff.


--- End Message ---
--- Begin Message ---
On 20 Nov 2011 at 10:36, Tommy Pham <tommy...@gmail.com> wrote: 

> I think you're approaching this the wrong way.
> 1) have a clear understanding of PHP - syntax, capabilities, etc.

That's what I'm doing - gathering information about bits of PHP that I've not 
used (or not used very much) before to see how my new setup could be structured.

> 2) have a clear understand of what you're intending to do -
> application's function/purpose, features, manageability,
> expandability, portability, etc...

I have a clear idea about *that*. I want to figure out if it's possible to use 
web sockets with a small server written in PHP to replace my current structure 
of ajax + apache + processes (which I suppose it forks). I see these benefits:

1) possible benefit - presumably when an ajax request arrives, a new process is 
started and so PHP has to be loaded and initialised each time. But perhaps this 
is in some way optimised so the PHP process is left running and apache then 
just tells it to read/execute a new script.

2) Definite benefit - when a browser makes an ajax request to run a script, it 
gets no information back until the script completes. Then it gets all of it. I 
have a couple of unsatisfactory workarounds for that in my existing structure. 
Websockets appears to offer a way for the browser to receive timely information.

> 3) understand design patterns

I don't know what this means.

> What your asking is practically impossible in any programming language
> akin to 'how to un-import packages in Java' or 'how to un-using
> namespace in C#'.  If you don't want to use it, don't include it ;)

I do want to use it but would like to be able to replace it with a newer 
version. If there is no way to do this then that is a data point.

And here's another question. Can a child forked by pcntl_fork() use a socket 
that the parent obtained? Reading the socket stuff in the PHP doc, there are a 
number of user-supplied notes hinting this might be problematic.

--
Cheers  --  Tim

--- End Message ---
--- Begin Message ---
On Mon, Nov 21, 2011 at 3:34 AM, Tim Streater <t...@clothears.org.uk> wrote:

> On 20 Nov 2011 at 10:36, Tommy Pham <tommy...@gmail.com> wrote:
>
> > I think you're approaching this the wrong way.
> > 1) have a clear understanding of PHP - syntax, capabilities, etc.
>
> That's what I'm doing - gathering information about bits of PHP that I've
> not used (or not used very much) before to see how my new setup could be
> structured.
>
> > 2) have a clear understand of what you're intending to do -
> > application's function/purpose, features, manageability,
> > expandability, portability, etc...
>
> I have a clear idea about *that*. I want to figure out if it's possible to
> use web sockets with a small server written in PHP to replace my current
> structure of ajax + apache + processes (which I suppose it forks). I see
> these benefits:
>
> 1) possible benefit - presumably when an ajax request arrives, a new
> process is started and so PHP has to be loaded and initialised each time.
> But perhaps this is in some way optimised so the PHP process is left
> running and apache then just tells it to read/execute a new script.
>

Did you check http://php-fpm.org/


>
> 2) Definite benefit - when a browser makes an ajax request to run a
> script, it gets no information back until the script completes. Then it
> gets all of it. I have a couple of unsatisfactory workarounds for that in
> my existing structure. Websockets appears to offer a way for the browser to
> receive timely information.
>
> > 3) understand design patterns
>
> I don't know what this means.
>
> > What your asking is practically impossible in any programming language
> > akin to 'how to un-import packages in Java' or 'how to un-using
> > namespace in C#'.  If you don't want to use it, don't include it ;)
>
> I do want to use it but would like to be able to replace it with a newer
> version. If there is no way to do this then that is a data point.
>
> And here's another question. Can a child forked by pcntl_fork() use a
> socket that the parent obtained? Reading the socket stuff in the PHP doc,
> there are a number of user-supplied notes hinting this might be problematic.
>
> --
> Cheers  --  Tim
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>



-- 
Shiplu Mokadd.im
Follow me, http://twitter.com/shiplu
Innovation distinguishes between follower and leader

--- End Message ---
--- Begin Message ---
Tim Streater <t...@clothears.org.uk> wrote:

> At the moment I'm using an instance of apache to run PHP scripts, as
> and when required via AJAX. Having got some understanding of web
> sockets, I'm minded to look at having a small server to execute these
> functions as required. The scripts, some 50 or so, are only about
> 300kbytes of source code, which seems small enough that it could all
> be loaded with include, as in:
 
> 
> <?php
> $fn = 'wiggy.php';
> include $fn;
> ?>
> 
> This appears to work although I couldn't see it documented.

I'm really not sure what you're looking for here -- that is pretty
standard php practice to load php files with include -- what were you
expecting here?

While it's certainly possible to rig up something using sockets, I don't
think that's how AJAX works, and you'd need a JS library that did.

As an alternative, can you set up a lightweight web server like lighttpd
and fastcgi on your host machine? This should give you the speed and
flexibility without incurring the overhead of loading everything into
mod_php under apache. The alternate server would listen on a different
port and dispatch fastcgi to deal with the php scripts.

As well, you could run fastcgi from apache to dispatch the smaller
scripts if you didn't want another web server running, although in
practice this hasn't proven to be an issue for me.

> I'd also like to be able to replace a module without restarting the
> server. I couldn't see a way to drop an included file, do I therefore
> take it that there is none? Failing that, is there a good way to
> dynamically replace parts of a PHP program, possibly using runkit?
 

Generally, you should only really need to dynamically replace parts of a
long-running program if you don't want to restart it. However, php
scripts are not long-running programs in general, unlike the apache
server itself, for example, and certainly if the php scripts are running
under apache, they will be time- and space-limited by whatever is set in
the php.ini file. If these little scripts are merely responding to AJAX
requests, they should be really short-lived.

OTOH, if you do have a need to replace an include file, you can include
it again unless you use something like "include_once" or
"require_once". Otherwise, the bare "include" and "require" commands
will merrily go ahead and re-include the file. What you really need to
watch out for is dealing with initialization of variables in the include
file, and if what you're including are classes that the previous version
has objects out for, what happens then is going to be pretty strange.

--- End Message ---

Reply via email to