onlyican Posted February 2, 2010 Share Posted February 2, 2010 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 More sharing options...
trq Posted February 2, 2010 Share Posted February 2, 2010 Have you looked at ob_flush? Its not exactly reliable but its likely the best you will get. http isn't exactly designed for what your doing. Link to comment https://forums.phpfreaks.com/topic/190648-output-buffer-while-page-loading/#findComment-1005434 Share on other sites More sharing options...
onlyican Posted February 2, 2010 Author Share Posted February 2, 2010 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. Link to comment https://forums.phpfreaks.com/topic/190648-output-buffer-while-page-loading/#findComment-1005436 Share on other sites More sharing options...
trq Posted February 2, 2010 Share Posted February 2, 2010 Could the issue be this is a script not a web page, thus no HTM headers? If this is being executed via a web server, headers are being sent. You'll want to use ob_flush within your loop to continually flush the output. Link to comment https://forums.phpfreaks.com/topic/190648-output-buffer-while-page-loading/#findComment-1005442 Share on other sites More sharing options...
onlyican Posted February 2, 2010 Author Share Posted February 2, 2010 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? Link to comment https://forums.phpfreaks.com/topic/190648-output-buffer-while-page-loading/#findComment-1005445 Share on other sites More sharing options...
trq Posted February 2, 2010 Share Posted February 2, 2010 Like I said, http isn't really made for what you want. Your best option would likely be to redesign your logic around ajax requests. Link to comment https://forums.phpfreaks.com/topic/190648-output-buffer-while-page-loading/#findComment-1005449 Share on other sites More sharing options...
onlyican Posted February 2, 2010 Author Share Posted February 2, 2010 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 Link to comment https://forums.phpfreaks.com/topic/190648-output-buffer-while-page-loading/#findComment-1005450 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.