php-general Digest 29 Jan 2011 16:15:41 -0000 Issue 7157

Topics (messages 311066 through 311079):

"public static" or "static public"?
        311066 by: Colin Guthrie
        311067 by: Fernando
        311072 by: Mujtaba Arshad
        311073 by: David Harkness

Counting Online users, but not using a Session Table in MySQL
        311068 by: AmirBehzad Eslami
        311069 by: Fernando
        311070 by: Jim Lucas
        311074 by: AmirBehzad Eslami
        311075 by: David Harkness
        311076 by: Marc Guay
        311077 by: David Harkness
        311078 by: Jim Lucas

Re: String Encodings - loose guidelines
        311071 by: Donovan Brooke

95th percentile of an array.
        311079 by: Paul Halliday

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 ---
OK, so it's a Friday hence a random debate....


What is preferred for class methods?

class foo
{
 static public function bar(){}

 public static function wibble(){}
}

??

All methods are valid, but are some more valid than others? :p

Checking ZF:

[colin@jimmy Zend (working)]$ cgrep "public static function" . |wc -l
755
[colin@jimmy Zend (working)]$ cgrep "static public function" . |wc -l
60

It's clear which is preferred there, but still not absolutely consistent
(I didn't bother checking differently scoped methods).


I personally prefer scope first then "static", but others may have valid
reasons/arguments for preferring the other way.

WDYT?

Col



-- 

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mageia Contributor [http://www.mageia.org/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


--- End Message ---
--- Begin Message --- I personally like scope static fucntion. Coming from C# it just makes more sense to me.

JF.

On 28/01/2011 12:15, Colin Guthrie wrote:
OK, so it's a Friday hence a random debate....


What is preferred for class methods?

class foo
{
  static public function bar(){}

  public static function wibble(){}
}

??

All methods are valid, but are some more valid than others? :p

Checking ZF:

[colin@jimmy Zend (working)]$ cgrep "public static function" . |wc -l
755
[colin@jimmy Zend (working)]$ cgrep "static public function" . |wc -l
60

It's clear which is preferred there, but still not absolutely consistent
(I didn't bother checking differently scoped methods).


I personally prefer scope first then "static", but others may have valid
reasons/arguments for preferring the other way.

WDYT?

Col




--- End Message ---
--- Begin Message ---
Having learned java before even knowing what php was (yeah I'm a noob in
both) I prefer scope static function.

On Fri, Jan 28, 2011 at 12:20 PM, Fernando <[email protected]> wrote:

> I personally like scope static fucntion.  Coming from C# it just makes more
> sense to me.
>
> JF.
>
>
> On 28/01/2011 12:15, Colin Guthrie wrote:
>
>> OK, so it's a Friday hence a random debate....
>>
>>
>> What is preferred for class methods?
>>
>> class foo
>> {
>>  static public function bar(){}
>>
>>  public static function wibble(){}
>> }
>>
>> ??
>>
>> All methods are valid, but are some more valid than others? :p
>>
>> Checking ZF:
>>
>> [colin@jimmy Zend (working)]$ cgrep "public static function" . |wc -l
>> 755
>> [colin@jimmy Zend (working)]$ cgrep "static public function" . |wc -l
>> 60
>>
>> It's clear which is preferred there, but still not absolutely consistent
>> (I didn't bother checking differently scoped methods).
>>
>>
>> I personally prefer scope first then "static", but others may have valid
>> reasons/arguments for preferring the other way.
>>
>> WDYT?
>>
>> Col
>>
>>
>>
>>


-- 
Mujtaba

--- End Message ---
--- Begin Message ---
On Fri, Jan 28, 2011 at 10:35 AM, Mujtaba Arshad <[email protected]>wrote:

> Having learned java before even knowing what php was (yeah I'm a noob in
> both) I prefer scope static function.


I learned Java first, too, and also prefer the scope first. I place a scope
on every method, so I'd rather the first word always be the scope rather
than sometimes scope, sometimes static. I also think of it as a "static
function" that happens to be "public." Finally, I prefer to group static
members at the top of the class to differentiate them as a separate API for
the class itself.

--- End Message ---
--- Begin Message ---
Dear list,

The common solution for counting online users is to store sessions in a Table.
I've created a Table in MySQL to acheive the result, but it seems this solution
is a little heavy for such a simple task.

Is there a better alternative? Can I use SqlLite to make COUNT(*) queries based
on a where statement?

Is there any better solution? Do you know any way to store sessions in Memory?

Does Memcache support counting sessions?

I'm looking for a high-performance solution to count online users.
What do you think?

-- 
Kind regards,
-behzad

--- End Message ---
--- Begin Message --- How did you created the table? Can you count the Id's only? Wouldn't this just count the entries in the index?

On 28/01/2011 12:57, AmirBehzad Eslami wrote:
Dear list,

The common solution for counting online users is to store sessions in a Table.
I've created a Table in MySQL to acheive the result, but it seems this solution
is a little heavy for such a simple task.

Is there a better alternative? Can I use SqlLite to make COUNT(*) queries based
on a where statement?

Is there any better solution? Do you know any way to store sessions in Memory?

Does Memcache support counting sessions?

I'm looking for a high-performance solution to count online users.
What do you think?


--- End Message ---
--- Begin Message ---
On 1/28/2011 9:57 AM, AmirBehzad Eslami wrote:
> Dear list,
> 
> The common solution for counting online users is to store sessions in a Table.
> I've created a Table in MySQL to acheive the result, but it seems this 
> solution
> is a little heavy for such a simple task.
> 
> Is there a better alternative? Can I use SqlLite to make COUNT(*) queries 
> based
> on a where statement?
> 
> Is there any better solution? Do you know any way to store sessions in Memory?
> 
> Does Memcache support counting sessions?
> 
> I'm looking for a high-performance solution to count online users.
> What do you think?
> 

The simple way that we do it is to have users table have a boolean field that
gets updated when a person logs in, then a time field showing when they last
visited.  These together should give you the information that you are looking 
for.

This gives you the idea...

SELECT  COUNT(*)
FROM    users_table
WHERE   logged_in = 't'
AND     last_activity > FROM_UNIXTIME( UNIX_TIMESTAMP() - 1800 )

Jim Lucas

--- End Message ---
--- Begin Message ---
Jim, I'm already using the solution you mentioned.

The problem is about the performance.
One solution is to increase the performance by using Memcached.

But counting online users always requires a __new__fresh__ COUNT(*) query, even
under Memcahched. Since the COUNT(*) result is very dynamic and could
change every second, it should not be cached.

I'm looking for a faster way to count online users.
COUNT(*) is time consuming under MySQL.

Any light-weight solutions?

--- End Message ---
--- Begin Message ---
If you're using memcached already you could store the number in it and
update it only when a user logs in/out. If no one is logging in/out, the
number isn't changing.

If your site is so popular that hundreds of users are logging in every
second you might want to change the logic so that the process to update the
count only does so when it has expired from the cache and give it a short
expiry time. At that point you probably would want each machine to track its
own number to avoid frequent distribution costs.

In the end I think you're going to have to get comfortable with the idea
that the number will never be exact. If you want exact, you have to pay for
it.

David

--- End Message ---
--- Begin Message ---
> I'm looking for a faster way to count online users. COUNT(*) is time 
> consuming under MySQL.

If COUNTing is the heavy part, why not create a 'users_logged_in'
field somewhere and increment it when someone logs in and decrement it
when someone logs out?  Then your query is just a straight SELECT.
Just chucking a thought out there.

Marc

--- End Message ---
--- Begin Message ---
On Fri, Jan 28, 2011 at 11:03 AM, Marc Guay <[email protected]> wrote:

> If COUNTing is the heavy part, why not create a 'users_logged_in'
> field somewhere and increment it when someone logs in and decrement it
> when someone logs out?  Then your query is just a straight SELECT.


If this is like most web sites, users don't usually log out--they just stop
requesting pages. With no logout event to decrement the count you need some
other way to stop counting a particular user such as 30 minutes after they
logged in. This is easily handled in a query on the users table, but it
causes performance issues.

David

--- End Message ---
--- Begin Message ---
On 1/28/2011 11:23 AM, David Harkness wrote:
> On Fri, Jan 28, 2011 at 11:03 AM, Marc Guay <[email protected]> wrote:
> 
>> If COUNTing is the heavy part, why not create a 'users_logged_in'
>> field somewhere and increment it when someone logs in and decrement it
>> when someone logs out?  Then your query is just a straight SELECT.
> 
> 
> If this is like most web sites, users don't usually log out--they just stop
> requesting pages. With no logout event to decrement the count you need some
> other way to stop counting a particular user such as 30 minutes after they
> logged in. This is easily handled in a query on the users table, but it
> causes performance issues.
> 
> David
> 

cron it.

Setup a cron script that runs every 5 minutes.

A seconds work every 5 minutes isn't too much is it?

Jim Lucas

--- End Message ---
--- Begin Message ---
Marc Guay wrote:
1.) Saving strings to a database

One thing I always forget to remember is to send tge "SET NAMES utf8"
command to MySQL after making a connection.  This will save you 1000
headaches if you're working with non-latin characters.  I can't count
the number of times I've thrown htmlentities, htmlspecialchars,
utf8_encode/decode/, stripslashes, etc, etc around trying to figure
out why those É's aren't being saved or read properly.  I imagine this
might fall into the category of "best practice".

Marc


Thanks for the heads up!

Donovan


--
D Brooke

--- End Message ---
--- Begin Message ---
What is the quickest way to do this? Will stats_stat_percentile work?
If so, does anyone have examples of its operation?

Keep in mind that my math is terrible. Use small words :)

Thanks.

-- 
Paul Halliday
http://www.pintumbler.org

--- End Message ---

Reply via email to