Jump to content

Output buffer while page loading


onlyican

Recommended Posts

Hey all

Quick question.

I have a script which is like a bot, it is running through the database checking about 8000 links to see of the link still exists, if the page had redirected (301, 302, 303) or if the site is down.

 

I just executed the script and monitored the Database it is writing to.

Sweet the DB contains all the records I asked it to (set a limit of 1000)

But the page never loaded.

 

As it loops through each record, it checks the record and writes to the DB and the screen.

HOw do I show this on the screen as soon as i echo that point, instead of waiting till the end of the script.

Link to comment
https://forums.phpfreaks.com/topic/190648-output-buffer-while-page-loading/
Share on other sites

if I stick ob_flush() at the top of the script it still waits till the end to show everything.

 

Could the issue be this is a script not a web page, thus no HTM headers?

Example snippet

ob_flush();
set_time_limit(3600); //Set the Time Limit to HIGH
ini_set('memory-limit', '16M'); //Set the Memory Limit
require("cls_linkchecker.php"); //Include Class

//Set DB Constants

define('DB_HOST', 'localhost');
define('DB_USER', 'come_on');
define('DB_PASS', 'I AINT THAT STUPID');
define('DB_NAME', 'my_db_name_here');


$objLinkChecker = new LinkChecker(); //Start Class
//Get all records that have not been checked within the last 3 days (Script due to run once a week)
$dateCheckBefore = date("Y-m-d H:m:s", strtotime('-3 days'));  

$strSQL  = "SELECT ContentID, URL FROM contenttbl WHERE ContentID NOT IN (SELECT ContentID FROM conUpdates WHERE UpdateTime > '".$dateCheckBefore."') ORDER BY ContentID LIMIT 0, 30"; //set to 30 for testing output

$db = mysql_connect(DB_HOST, DB_USER, DB_PASS);
mysql_select_db(DB_NAME, $db);
$objResult = mysql_query($strSQL, $db);

if(!$objResult){
    echo "There has been an error<br />".mysql_error();
    die();
}
   
//Loop Through Results    
while($row = mysql_fetch_assoc($objResult)){

    $intForSale         = 0; //Default setting Flags
    $intWebsiteDown     = 0;
    
    $objLinkChecker->setNewURL($row["URL"]);
    $intContentID       = $row["ContentID"];
    $strWebContent      = $objLinkChecker->getWebContent();
    $intNumRedirects    = $objLinkChecker->getNumRedirects();
    $arrWebInfo         = $objLinkChecker->getWebInfo();
    $intOrigHttp        = $objLinkChecker->getOrigHTTPCode();
    $intNewHttp         = $arrWebInfo["http_code"];
    $strNewURL          = $arrWebInfo["url"];

    if($intNewHttp == 302){
        $intForSale = 1; //IF we are still returning a 302, the website appears to be moved and pending sale
    }
    if($intNewHttp == 0){
        $intWebsiteDown = 1; //If we are not getting a response, the website appears to be offline
    }
    
    $objLinkChecker->saveEntry(DB_HOST, DB_USER, DB_PASS, DB_NAME, $intOrigHttp, $intNewHttp, $row["URL"], $strNewURL, $intForSale, $intWebsiteDown, $intContentID);
}

 

Within the class, I am using cURL to get the page headers and some other checks.

Yes I know Headers are sent, I meant DocType, <html><head> ect

 

I am used to ASP where we put the output_buffer = true at the top.

 

Anyway

I tried ob_flush at start of while loop - fail

End of while loop - fail

The line after my echo statement within the class - fail

 

Any other suggestions?

I would do but this is just a quick script I built to get the latest information on the Websites.

Normally this would be run Sunday Mornings when I am tucked up in bed, so not that bothered about a re-build with Ajax.

 

Just wanted a quick fix with results.

 

Cheers anyway

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.