Slow application

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Wolfie
Forum Commoner
Posts: 37
Joined: Wed Jan 28, 2009 8:40 am
Location: Poland

Slow application

Post by Wolfie »

Hi all,

I don't know if it is correct part of formum for this topic but I will try.....if not please move to proper part.


I have some aplication - mail client which is very slow because of imap_open function repetition each time calling request.

This is MVC architecture, all request goes thru index.php than to controllers which perform actions.

For example while sending login and password it goes to mailbox function which looks like this :

Code: Select all

 
function mailbox() {
                $_SESSION['login'] =  $_POST['mailbox'];
                $_SESSION['pass'] = $_POST['pass'];
                if(($this->model->connect('gmail.com',$_SESSION['login'],$_SESSION['pass'],'993','imap')) == false) {
                    $this->view = new LoginView;
                    $this->view->display('login');
                    echo 'Wrong login or/and password!';
                } else {
                    //echo 'Loged!';
                    $this->model->inbox();
                    $view = new LoginView;
                    $boxes = $this->model->getMailboxes();
                    $msgsParts = $this->model->getMsgsParts(333);
                    $view->setVars('boxes', $boxes);
                    $view->setVars('parts',$msgsParts);
                    $view->display($_POST['action']);
                }
        }
 
Here we have the line :

Code: Select all

 
$this->model->connect('gmail.com',$_SESSION['login'],$_SESSION['pass'],'993','imap')
 
Which is the model function containing imap_open php function

Than when the user wants to see the specific message he is sending the request over bootstrap (index.php) to other controller which looks like this :

Code: Select all

 
function mailbox() {
            //echo 'MailboxController action mailbox!';
            print_r($_SESSION);
            $this->model->connect('gmail.com',$_SESSION['login'],$_SESSION['pass'],'993','imap');
            $this->model->reconnect($_POST['mailbox']);
            $view = new LoginView;
            $boxes = $this->model->getMailboxes();
            $msgsParts = $this->model->getMsgsParts(3);
            $view->setVars('boxes', $boxes);
            $view->setVars('parts',$msgsParts);
            $view->display($_POST['action']);
        }
        
        function message($params) {
            print_r($params['id']);
            $view = new LoginView;
            $this->model->connect('gmail.com',$_SESSION['login'],$_SESSION['pass'],'993','imap');
            $view->setVars('message', $this->model->getMessage($params['id']));
            $view->display('message');
        }
 
As u can see in every function I have to call the model to connect to mail server with imap_open and this takes enormous amount of time, about 5 sec while changing mailbox (INBOX, Spambox ect.) and one second to see the specific message.

Any idea how to accelerate the application ?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Slow application

Post by Christopher »

Moved to PHP Code.
(#10850)
Post Reply