Fetching logged in users using PHP

Author Message

Damien MARTIN

Thursday 14 January 2010 12:53:41 am

Hi there,

I have a problem fetching users and filtering them by "logged in" status :

$membres = eZContentObjectTreeNode::subTreeByNodeID(false, 253);
            
foreach($membres as $membre){
                
    $usr = eZUser::instance($membre->ContentObjectID);
    $nod = eZContentObject::fetch($membre->ContentObjectID);
                
    if($usr->isLoggedIn() == true)
        $liste[] = array("nom" => $nod->Name, "id" => $nod->ID);
                
}

But when I look to my $liste, everybody is in, although everybody is not logged in. (verified in the administration panel)

For information, I really need this code because I need to filter the users by another added attribute too. And as the web site will have a lot of users. I prefer to do this kind of operations directly in PHP and not with the template language (for speed).

Thanks,

Damien

Gaetano Giunta

Thursday 14 January 2010 1:14:22 am

If speed is your concern, I'd suggest going for a custom sql request; With many users the above code will be doing a huge amount of queries, wasting time and memory...

Principal Consultant International Business
Member of the Community Project Board

Bertrand Dunogier

Thursday 14 January 2010 1:21:30 am

I'm not sure why this would fail, but it might be more efficient to use eZUser::fetchLoggedInList(). But maybe you need to filter this list out by group, in which case custom code would indeed be required.

Bertrand Dunogier
eZ Systems Engineering, Lyon
http://twitter.com/bdunogier
http://gplus.to/BertrandDunogier

Damien MARTIN

Thursday 14 January 2010 1:46:42 am

@Gaetano

I would like to create custom SQL queries but I don't have the time for now to look at the database.
I looked some months ago for a diagramm with all the tables and relations of the eZ database but unsuccessfully.

@Bertrand

eZUser::fetchLoggedInList() works very well for what I want to do. I just now have to fetch using eZContentObject::fetch() and all the datas I need are there.
I suppose it would be faster with this method (no more need to fetch eZUser).
I don't know when I haven't tried this method before...

Thank you very much guys !

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 02:02:45
Script start
Timing: Jan 18 2025 02:02:45
Module start 'layout'
Timing: Jan 18 2025 02:02:45
Module start 'content'
Timing: Jan 18 2025 02:02:46
Module end 'content'
Timing: Jan 18 2025 02:02:46
Script end

Main resources:

Total runtime0.6561 sec
Peak memory usage4,096.0000 KB
Database Queries62

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0057 589.0547152.6250
Module start 'layout' 0.00570.0030 741.679739.4609
Module start 'content' 0.00870.6457 781.1406603.1719
Module end 'content' 0.65440.0016 1,384.312512.1563
Script end 0.6560  1,396.4688 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00360.5456160.0002
Check MTime0.00140.2207160.0001
Mysql Total
Database connection0.00060.090710.0006
Mysqli_queries0.595590.7651620.0096
Looping result0.00060.0864600.0000
Template Total0.626495.520.3132
Template load0.00230.355420.0012
Template processing0.624195.117920.3120
Template load and register function0.00010.019710.0001
states
state_id_array0.00100.157910.0010
state_identifier_array0.00090.134420.0004
Override
Cache load0.00190.2933290.0001
Sytem overhead
Fetch class attribute can translate value0.00070.109630.0002
Fetch class attribute name0.00150.230470.0002
XML
Image XML parsing0.00140.216230.0005
class_abstraction
Instantiating content class attribute0.00000.003880.0000
General
dbfile0.00100.1577280.0000
String conversion0.00000.001440.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
4content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
4content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
7content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
1content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
2content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1content/datatype/view/ezxmltags/emphasize.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/emphasize.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 21
 Number of unique templates used: 8

Time used to render debug report: 0.0001 secs