EllisLab text mark
Advanced Search
3 of 10
3
   
The Authentication Library 1.0.6
Posted: 02 October 2009 05:06 PM   [ Ignore ]   [ # 41 ]   [ Rating: 0 ]
Joined: 2009-09-25
5 posts

Well if i run a page without Auth it loads in a 1/3 of a second.

If i load the page with auth it takes 2.3 seconds.

Immediately I thought it would be the database access that Auth is doing, but the profiler tells me the queries are returning very quickly.

At this point I think it’s almost certainly an issue with how I am doing things, some configuration issue. 

Surely it’s not expected that using auth adds 2 seconds to page load time.

Update : It’s only slow when I’m logged in.

 
Posted: 02 October 2009 05:34 PM   [ Ignore ]   [ # 42 ]   [ Rating: 0 ]
Avatar
Joined: 2009-06-19
6267 posts

It is not the database causing it,  look at the size of the Auth library being loaded.

Anytime you load a library etc the timming is going to take longer.

Sure you have 1/3 seconds.

But now you are loading the Auth library form validation library session library, Auth model, Auth helper form helper url helper email helper and Auth lang.

1 second more is great for what Auth is loading speed wise.

Enjoy
InsiteFX

 Signature 

Ceritfied State of CT Computer Programming Teacher.
Custom Designed Icons, eBook Covers Software Boxes. CD, DVD Etc. New iPhone® Tab Bar Icons and iPhone® Applications Icons.

STOP! Before posting your questions, remember the WWW Golden rule:
What did you try? What did you get? What did you expect to get?

Input -> Controller | Processing -> Model | Output -> View

 
Posted: 05 October 2009 07:31 AM   [ Ignore ]   [ # 43 ]   [ Rating: 0 ]
Avatar
Joined: 2008-05-04
356 posts

The Authentication Library shouldn’t be adding that much time to your application. InsiteFX is on the right track saying there will be some added time to your application, but two seconds is a nightmare.

What version of PHP are you running?
What version of CodeIgniter are you running?
Are you sure you’re on The Authentication Library 1.0.6?
Are there any other bottlenecks in your application?
Where are you seeing this time addition? Everywhere? Only on the admin panel?


Thanks,
Adam

 Signature 

[ Adam Griffiths - Freelance Web Applications Developer ]
[ Follow me on Twitter ]

 
Posted: 07 October 2009 03:55 AM   [ Ignore ]   [ # 44 ]   [ Rating: 0 ]
Joined: 2009-09-25
5 posts

Thanks for your interest Adam.

I am going to do some more research, I expect the problem is with what I am doing, rather than the library itself.

If I can figure it out I will post what the solution was in case it helps others. 

If I can’t I will come back with more details looking for help smile

I am using
Auth 1.0.6 and the latest version of codeigniter

Loading Time Base Classes     0.0161
Controller Execution Time ( sited / Index )    5.0919
Total Execution Time     5.1081

The auth sessions query and user set identifier SQL queries are very fast, not half a second in total.

All my pages are very slow if I am logged in, but fast if I am logged out.  I suspect it’s maybe something to do with apache and sessions.

Cheers
Sam

 
Posted: 07 October 2009 09:53 AM   [ Ignore ]   [ # 45 ]   [ Rating: 0 ]
Avatar
Joined: 2009-06-19
6267 posts

Are you using normal session or CI database sessions?

Enjoy
InsiteFX

 Signature 

Ceritfied State of CT Computer Programming Teacher.
Custom Designed Icons, eBook Covers Software Boxes. CD, DVD Etc. New iPhone® Tab Bar Icons and iPhone® Applications Icons.

STOP! Before posting your questions, remember the WWW Golden rule:
What did you try? What did you get? What did you expect to get?

Input -> Controller | Processing -> Model | Output -> View

 
Posted: 07 October 2009 10:12 AM   [ Ignore ]   [ # 46 ]   [ Rating: 0 ]
Joined: 2009-09-28
4 posts

Hi all…

Using this library, i have noticed that inside the ci_sessions table, ip_address is 0.0.0.0

anything wrong here? how would i fix it?

thanks!

 
Posted: 07 October 2009 12:48 PM   [ Ignore ]   [ # 47 ]   [ Rating: 0 ]
Avatar
Joined: 2008-05-04
356 posts
Raykoid666 - 07 October 2009 02:12 PM

Hi all…

Using this library, i have noticed that inside the ci_sessions table, ip_address is 0.0.0.0

anything wrong here? how would i fix it?

thanks!

The CodeIgniter Session Library uses 0.0.0.0 when a valid IP address isn’t given.

 

Thanks,
Adam

 Signature 

[ Adam Griffiths - Freelance Web Applications Developer ]
[ Follow me on Twitter ]

 
Posted: 07 October 2009 06:03 PM   [ Ignore ]   [ # 48 ]   [ Rating: 0 ]
Joined: 2009-09-28
4 posts

thanks for the reply adam,

another question here: when and how exactly are the forms processed? like i see the registration function inside the auth library loads the registration view, but also processes it, but i can’t quite figure out how.

I need so somehow return TRUE if it’s processed successfully, for registration, login, ... since i want to use jQuery together with this library.

thanks,
Kenny

 
Posted: 07 October 2009 06:43 PM   [ Ignore ]   [ # 49 ]   [ Rating: 0 ]
Avatar
Joined: 2008-05-04
356 posts
Raykoid666 - 07 October 2009 10:03 PM

thanks for the reply adam,

another question here: when and how exactly are the forms processed? like i see the registration function inside the auth library loads the registration view, but also processes it, but i can’t quite figure out how.

I need so somehow return TRUE if it’s processed successfully, for registration, login, ... since i want to use jQuery together with this library.

thanks,
Kenny

If you open up the file libraries/Auth.php – you can see the two functions in there, login() and register(). That’s how it all works.

You could add some code into that file to shoot off a call to jQuery so when a user is registered/logged in you can do what you like with it.

Yes it’s not pretty but it’s the only way I can think of.


Thanks,
Adam

 Signature 

[ Adam Griffiths - Freelance Web Applications Developer ]
[ Follow me on Twitter ]

 
Posted: 08 October 2009 09:10 AM   [ Ignore ]   [ # 50 ]   [ Rating: 0 ]
Joined: 2009-10-07
2 posts
samhQC - 07 October 2009 07:55 AM

Thanks for your interest Adam.

I am going to do some more research, I expect the problem is with what I am doing, rather than the library itself.

If I can figure it out I will post what the solution was in case it helps others. 

If I can’t I will come back with more details looking for help smile

I am using
Auth 1.0.6 and the latest version of codeigniter

Loading Time Base Classes     0.0161
Controller Execution Time ( sited / Index )    5.0919
Total Execution Time     5.1081

The auth sessions query and user set identifier SQL queries are very fast, not half a second in total.

All my pages are very slow if I am logged in, but fast if I am logged out.  I suspect it’s maybe something to do with apache and sessions.

Cheers
Sam

Hi, I think your problem may be related to Auth connecting to random.org in Auth.php line 340, method _generate(). Try commenting the first two options and leave the internal generator and see what happends.

 
Posted: 08 October 2009 10:41 AM   [ Ignore ]   [ # 51 ]   [ Rating: 0 ]
Joined: 2009-09-25
5 posts

jv1,

You are correct!

I commented out _generate() as you suggested and my page load times drop from ~2.2 seconds to .5 on localhost.

Thanks a lot, I’m not sure if there is a better long term fix, but this sure makes development faster.

Here is what the function now looks like :

    function _generate()
    {
      $username = $this->CI->session->userdata(‘username’);

      $rand_url = ‘http://random.org/strings/?num=1&len=20&digits=on&upperalpha=on&loweralpha=on&unique=on&format=plain&rnd=new’;
/*
      if (ini_get(‘allow_url_fopen’)) {
      // Grab the random string using the easy version if we can
      $token_source = fopen($rand_url, “r”);
      $token = fread($token_source, 20);
      } elseif (function_exists(‘curl_version’)) {
      // No easy version, so try cURL
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, $rand_url);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      $token = curl_exec($ch);
      curl_close($ch);
      } else {
        */
      // No love either way, generate a random string ourselves
      $length = 20;
        $characters = ‘0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ’;
        $token = ‘’; 
        for ($i = 0; $i < $length; $i++) {
          $token .= $characters[mt_rand(0, strlen($characters)-1)];
        }
      //}

      $identifier = $username . $token;
      $identifier = $this->_salt($identifier);

      $this->CI->db->query(“UPDATE `$this->user_table` SET `identifier` = ‘$identifier’, `token` = ‘$token’ WHERE `username` = ‘$username’”);

      setcookie(“logged_in”, $identifier, time()+3600, ‘/’);
    }

Cheers
Sam

 
Posted: 08 October 2009 11:23 AM   [ Ignore ]   [ # 52 ]   [ Rating: 0 ]
Joined: 2009-10-07
2 posts
samhQC - 08 October 2009 02:41 PM

jv1,

You are correct!

I commented out _generate() as you suggested and my page load times drop from ~2.2 seconds to .5 on localhost.

Thanks a lot, I’m not sure if there is a better long term fix, but this sure makes development faster.

...

Cheers
Sam

Well, the two seconds delay probably mean your site couldn’t resolv/connect to random.org and was only using the internal generator anyway smile

In php.net’s manual say this on the uniqid() function page:

Examples

If you need a unique identifier or token and you intend to give out that token
to the user via the network 
(i.esession cookies), it is recommended that you
use something along these lines:

This will create a 32 character identifier (a 128 bit hex numberthat is 
extremely difficult to predict
.

Example #1 uniqid() Example
<?php
// no prefix
// works only in PHP 5 and later versions
$token md5(uniqid());

// better, difficult to guess
$better_token md5(uniqid(mt_rand(), true));
?> 

But I’m not sure why it says it will only work with php5, as both functions are listed as php4/php5 compatible.

I’m considering using Auth but I don’t understand the rationaly behind connecting to an external site (random.org) to generate this token. Besides, the hosting provider I’m working with doesn’t support url_fopen or curl.

Most modern OSs should provide a reasonably good random generator. I’m working on OpenBSD and I’m sure it does, as most Linux distribs out there. I’m not so sure about it on the Windows systems.

Adam, are there other pieces of Auth that require external support? I don’t feel like reading it all smile

 
Posted: 08 October 2009 01:25 PM   [ Ignore ]   [ # 53 ]   [ Rating: 0 ]
Joined: 2009-09-28
4 posts

If you open up the file libraries/Auth.php – you can see the two functions in there, login() and register(). That’s how it all works.

You could add some code into that file to shoot off a call to jQuery so when a user is registered/logged in you can do what you like with it.

Yes it’s not pretty but it’s the only way I can think of.


Thanks,
Adam

Yes I know , though the problem is I don’t know exactly where to add the code. That actually was the problem in the first place. I’d have to include a true, and if it fails, somehow capture the error messages.

I guess all in all, the problem is i don’t quite yet fully understand your coding, as in, the way you put the functions together.

Thanks,
Kenny

 
Posted: 08 October 2009 01:35 PM   [ Ignore ]   [ # 54 ]   [ Rating: 0 ]
Avatar
Joined: 2008-05-04
356 posts
Raykoid666 - 08 October 2009 05:25 PM

If you open up the file libraries/Auth.php – you can see the two functions in there, login() and register(). That’s how it all works.

You could add some code into that file to shoot off a call to jQuery so when a user is registered/logged in you can do what you like with it.

Yes it’s not pretty but it’s the only way I can think of.


Thanks,
Adam

Yes I know , though the problem is I don’t know exactly where to add the code. That actually was the problem in the first place. I’d have to include a true, and if it fails, somehow capture the error messages.

I guess all in all, the problem is i don’t quite yet fully understand your coding, as in, the way you put the functions together.

Thanks,
Kenny

Those functions follow the pattern laid out in the user guide for the Form Validation Library, here. Have a read of that, it should clear everything up.


Thanks,
Adam

 Signature 

[ Adam Griffiths - Freelance Web Applications Developer ]
[ Follow me on Twitter ]

 
Posted: 09 October 2009 04:44 AM   [ Ignore ]   [ # 55 ]   [ Rating: 0 ]
Joined: 2007-10-17
1 posts

Github seems to be freezing on loading http://www.google-analytics.com lol.. from here anyway

 
3 of 10
3