0

I am using Codeigniter and including Facebook library to implement Facebook authentication. I am autoloading the library as:

$autoload['libraries'] = array('database', 'session', 'facebook_lib', 'aescryption');

And the facebook_lib.php library is calling facebook.php (which in turn calls base_facebook.php). Now, this is making the site very slow. It takes around 4-8 seconds to load pages on my localhost. I didn't knew this earlier. The pages were loading really slow. I then profiled the application and found that even if I am just calling a blank page it was really slow. I then thought that something else is going on and my first thought was the autoload configs. If I remove the 'facebook_lib' library then the page loads right away.

Any ideas what can be done here? Has anyone encountered a similar problem?

Thanks.

UPDATE:

Here is the code that I have in facebook library: $this->ci =& get_instance();

    // Create our Application instance
    //(replace this with your appId and secret).
    $this->ci->load->file(APPPATH.'/third_party/facebook.php');

    $this->data['facebook'] = new Facebook(array(
                                            'appId'  => $this->ci->config->item('fb_app_id'),
                                            'secret' => $this->ci->config->item('fb_secret_key')));

    $this->data['fb_user'] = $this->data['facebook']->getUser();

    if ($this->data['fb_user']) {           
     try {
            $this->data['$user_profile']=$this->data['facebook']->api('/me');
            $this->ci->load->model('login_signup_model');
            $this->ci->login_signup_model->storeFBUser($this->data['$user_profile']['id']);

            return true;
        } catch (FacebookApiException $e){
            error_log($e);
            $this->data['fb_user']=null;
        }
     }
Blueboye
  • 1,374
  • 4
  • 24
  • 49
  • "I then profiled the application and found that even if I am just calling a blank page it was really slow" --- and what **actually** makes it slow? Profiling should show you the exact problem place. – zerkms Aug 19 '12 at 21:24
  • The facebook_lib. I have facebook_lib mentioned in the autoload configuration file. So, every time a page load, it autoloads the facebook library (that I am using for FB Authentication). When I profiled, all the db queries took few millisecs and there was nothing that made it evident that something in the controller is making it slow. So, I figured out by hit and trial that the FB library is making the app slow. – Blueboye Aug 19 '12 at 21:25
  • it's not helpful at all. The library itself does nothing, so loading it takes milliseconds. Perform **real** profiling and see the **exact code** that makes your app slow. "that the FB library is making the app slow" --- well, it's not true. Not the library, but some FB API requests do that – zerkms Aug 19 '12 at 21:27
  • Update my original post with the code that I have in my facebook library file. The problem seems like that I am checking the user on every page load if they are logged in or not. And, I have to. isn't it? – Blueboye Aug 19 '12 at 21:29
  • So you perform a request(s) to FB API. It takes some time. Does "buy the faster broadband connection" count as an answer? – zerkms Aug 19 '12 at 21:30
  • Nope. I cannot tell users to get faster broadbands. And anyways, there is something wrong with the code that is increasing the page load time. It is not the internet speed that is the problem here. – Blueboye Aug 19 '12 at 21:33
  • "Nope. I cannot tell users to get faster broadbands." --- your users have nothing to do with this - the requests are performed by server. "And anyways, there is something wrong with the code that is increasing the page load time" --- you're performing requests to a remote API, it takes some time. "It is not the internet speed that is the problem here" --- how would you know if you haven't profiled your code? – zerkms Aug 19 '12 at 21:34
  • 1
    _“The problem seems like that I am checking the user on every page load if they are logged in or not.”_ – no, that’s not the problem. That just reads a cookie to tell if there is a logged-in user, and that does not cost any significant amount of time. But you’re doing more than just that – you are reading the user info from Facebook every time again; and that’s an HTTP request, and therefor takes time. _“And, I have to. isn't it?”_ – no, you don’t have to read a user’s personal data on every request to your page. Save it into the session – and if it’s already in there, don’t request it again. – CBroe Aug 20 '12 at 08:49

0 Answers0