PHP page taking 3 minutes to load

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
nutkenz
Forum Contributor
Posts: 155
Joined: Tue Jul 19, 2005 12:25 pm

PHP page taking 3 minutes to load

Post by nutkenz »

Whenever I'm logged out of my session (which I also can't explain why it's happening) and reload the page, it takes about 3 full minutes for it to load, even though the PEAR timer claims otherwise:

Code: Select all

time index ex time % 
Start 1215786404.88426100 - 0.00% 
Auth: Start 1215786404.91293000 0.028669 50.09% 
Auth: Finish 1215786404.91962200 0.006692 11.69% 
ACL: Start 1215786404.91989000 0.000268 0.47% 
ACL: Finish 1215786404.91994300 0.000053 0.09% 
Stop 1215786404.94149500 0.021552 37.66% 
total - 0.057234 100.00% 
 
There's hardly any code being executed though... what could be causing this? It's not my internet connection because it's also happening on my localhost WIndows test server. Both servers run Apache.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: PHP page taking 3 minutes to load

Post by s.dot »

Are you on a shared server? It may be severely overloaded.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
nutkenz
Forum Contributor
Posts: 155
Joined: Tue Jul 19, 2005 12:25 pm

Re: PHP page taking 3 minutes to load

Post by nutkenz »

No, it's a dedicated server and it's not overloaded at all; the load is 0.18 / 4 on a Dual Core AMD Opteron(tm) Processor 270

Also, it's happening on my local Windows testing environment as well so it is probably not hardware related. I'm not sure where to start looking for the issue because the timer reports that the site is being processed in less than a second... I'm wondering why it takes the browser that long to process.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: PHP page taking 3 minutes to load

Post by s.dot »

Ping your servers and check the response times.
Post the code you're using.

Hm... don't really know what else to try. =/
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
nutkenz
Forum Contributor
Posts: 155
Joined: Tue Jul 19, 2005 12:25 pm

Re: PHP page taking 3 minutes to load

Post by nutkenz »

Here's the code which is involved when the session has expired and the login layout is called:

Project dispatcher (index.php):

Code: Select all

$page = $p["path"].".php";
 
// Access control
if (@$_REQUEST["logout"])
{
    $auth = Zend_Auth::getInstance();
    $auth->clearIdentity();
    
    flash(trl("You have been logged out."),"/admin");
}
elseif (!ALLOW_ACCESS)
{
    if ($userLogin = user("login"))
    {
        $msg["error"]->add(trl("$userLogin is not allowed to access this page. 
            Please upgrade to an account with higher security clearance."));
    }
    
    $p["layout"] = "none";
    include(LIB_LAYOUTS_PATH."login.php");
}
elseif (strstr($page,"pages") === false)
{
    // If we're not including a standard page (cron job) -> get output only
    $html = getData($_SERVER["HTTP_HOST"]."/".$page."?".$_SERVER["QUERY_STRING"]);
}
else // Process PHP page
{
    ob_start();
        include($page);
        $html = ob_get_contents();
    ob_end_clean();
}
 
$admin = true; // Use admin templates
include(LIB_DRIVERS_PATH."dispatch.php");
Library dispatcher (called at the end of the previous file):

Code: Select all

if (!empty($p["html"]))
{
    // Replace standard HTML
    $html = $p["html"];
}
 
if (!empty($p["layout"]) && $p["layout"] !== "none")
{
    $customLayout = LAYOUTS_PATH.$p["layout"].".php";
    
    if (file_exists($customLayout))
    {
        include($customLayout);
    }
    else // There is no custom layout defined
    {
        include(LIB_LAYOUTS_PATH.$p["layout"].".php");
    }
}
else echo @$html;
 
if (VERBOSE >= 2)
{
    $timer->display();
}
Auth.php:

Code: Select all

<?
 
$timer->setMarker("Auth: Start");
 
require_once('Zend'.DS.'Auth.php');
require_once('Zend'.DS.'Auth'.DS.'Storage'.DS.'Session.php');
require_once('Zend'.DS.'Auth'.DS.'Adapter'.DS.'DbTable.php');
 
$auth = Zend_Auth::getInstance();
$session = new Zend_Auth_Storage_Session("user");
$auth->setStorage($session);
 
$authDb = new Zend_Auth_Adapter_DbTable($db,'users','login','pass');
 
if (!empty($_REQUEST["auth_login"]))
{
    $login = $_REQUEST["auth_login"];
    $pass = $_REQUEST["auth_pass"];
}
else // No login attempted
{
    $login = $pass = null;
}
 
if (!empty($login) && !empty($pass))
{
    $authDb->setIdentity($login)->setCredential($pass);
    $result = $authDb->authenticate();
    
    if (!$result->isValid())
    {
        foreach ($result->getMessages() as $message)
        {
            $msg["error"]->add(trl($message));
        }
        // Invalidate existing data
        $auth->clearIdentity();
    }
    else // Logged in
    {
        Zend_Session::rememberMe(60*60*24*7);
        $auth->getStorage()->write($authDb->getResultRowObject(null,'pass'));
    }
}
 
$timer->setMarker("Auth: Finish");
 
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: PHP page taking 3 minutes to load

Post by Benjamin »

Have you checked for a load spike whenever a request is pending? That would indicate a faulty loop of some sort. Someone else was having this problem a while back and I believe they were using Zend as well. I don't believe there was a solution posted.
nutkenz
Forum Contributor
Posts: 155
Joined: Tue Jul 19, 2005 12:25 pm

Re: PHP page taking 3 minutes to load

Post by nutkenz »

There is no spike in the load.
nutkenz
Forum Contributor
Posts: 155
Joined: Tue Jul 19, 2005 12:25 pm

Re: PHP page taking 3 minutes to load

Post by nutkenz »

Any more suggestions on possible solutions to the long loading time?
Post Reply