Re: [PHP] Counting Online users, but not using a Session Table in MySQL

2011-01-28 Thread Jim Lucas
On 1/28/2011 11:23 AM, David Harkness wrote:
> On Fri, Jan 28, 2011 at 11:03 AM, Marc Guay  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

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



Re: [PHP] Counting Online users, but not using a Session Table in MySQL

2011-01-28 Thread David Harkness
On Fri, Jan 28, 2011 at 11:03 AM, Marc Guay  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


Re: [PHP] Counting Online users, but not using a Session Table in MySQL

2011-01-28 Thread Marc Guay
> 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

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



Re: [PHP] Counting Online users, but not using a Session Table in MySQL

2011-01-28 Thread David Harkness
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


Re: [PHP] Counting Online users, but not using a Session Table in MySQL

2011-01-28 Thread AmirBehzad Eslami
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?

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



Re: [PHP] "public static" or "static public"?

2011-01-28 Thread David Harkness
On Fri, Jan 28, 2011 at 10:35 AM, Mujtaba Arshad 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.


Re: [PHP] "public static" or "static public"?

2011-01-28 Thread Mujtaba Arshad
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  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


Re: [PHP] String Encodings - loose guidelines

2011-01-28 Thread Donovan Brooke

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

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



Re: [PHP] Counting Online users, but not using a Session Table in MySQL

2011-01-28 Thread Jim Lucas
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(*)
FROMusers_table
WHERE   logged_in = 't'
AND last_activity > FROM_UNIXTIME( UNIX_TIMESTAMP() - 1800 )

Jim Lucas

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



Re: [PHP] Counting Online users, but not using a Session Table in MySQL

2011-01-28 Thread Fernando
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?



Re: [PHP] "public static" or "static public"?

2011-01-28 Thread Fernando
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





[PHP] "public static" or "static public"?

2011-01-28 Thread Colin Guthrie
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/]


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



Re: [PHP] Pear Problems

2011-01-28 Thread Daniel Brown
On Fri, Jan 28, 2011 at 00:33, Ethan Rosenberg  wrote:
>
> Please take a look at php.ini in the vicinity of line 510.  You will see the
> construct to which I refer.  Can you explain what is going on?  I do not
> think it is a problem with commenting out a line.
>
> Any ideas from the rest of the list?

Keep in mind that php.ini is not universal, and changes
drastically with version, distribution, CLI vs. web, customization,
and more.  The answer that Adam gave you is absolutely correct with
regard to the information you provided.  You need to put a semicolon
before the line you quoted as being line 510 in your php.ini.  The
directive you want is error_reporting, and should look like so:

error_reporting = E_ALL & ~E_NOTICE

-- 

Network Infrastructure Manager
Documentation, Webmaster Teams
http://www.php.net/

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