and waiting and waiting. When launching a particular script localhost takes forever to find the server such that the script times out at 'set_time_limit (180);' without processing anything at all. Many times, the server ignores the time limit until Chrome dies and takes the computer with it.

I getting the following error messages for Chrome and Safari in the console:

7/17/13 9:04:20.012 AM WindowServer[230]: CGXDisableUpdate: UI updates were forcibly disabled by application "Google Chrome" for over 1.00 seconds. Server has re-enabled them.
7/17/13 9:04:21.687 AM WindowServer[230]: reenable_update_for_connection: UI updates were finally reenabled by application "Google Chrome" after 2.69 seconds (server forcibly re-enabled them after 1.01 seconds)

I walked this through the script:

error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
die('why does this not work?

and got no errors, and wouldn't you know nothing stalled.

Here's the code: I borrowed heavily from PHP-Excel. Here's the blooming details:
MacBook Pro, 2 GB memory, 160 GB HD,
Chrome 28.0.1500.71
Safari 6.0.5 (8536.30.1)
Apache2 2.2.22
MySQL: mysql-5.7.1-m11-osx10.7-x86_64

<?php
// I have tried the script with and without the following lines and nothing changes
session_name("PassTech");
session_start();
error_reporting (E_ERROR | E_WARNING | E_PARSE | E_NOTICE);  
set_time_limit (60); gc_enable(); // Enable Garbage Collector var_dump(gc_enabled()); // true var_dump(gc_collect_cycles()); // # of elements cleaned up gc_disable(); // Disable Garbage Collecto //ob_end_clean(); /** Error reporting */ error_reporting(E_ALL); ini_set('display_errors', TRUE); ini_set('display_startup_errors', TRUE); define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />'); date_default_timezone_set('Chicago/USA'); Do { $SystemNum = $_SESSION['SystemNum']; $System = $_SESSION['System']; $EndMO = $_SESSION['EndMO']; $FileName = $System . '--' . $EndMO . '.xlsx'; if($SystemNum == 0) $SystemNumEntry++; $_SESSION['SystemNumEntry'] = $SystemNumEntry; echo $SystemNumEntry; include "ImportCSV.php"; /** Include PHPExcel_IOFactory */ require_once '../Classes/PHPExcel/IOFactory.php'; // Save Excel 2007 file echo date('H:i:s') , " Write to Excel2007 format" , EOL; $callStartTime = microtime(true); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); //$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); $objWriter->save(str_replace('.php', '.xlsx', __FILE__)); $structure = '.classes/MonthlyReports/'; // To create the nested structure, the $recursive parameter // to mkdir() must be specified. $WriteFile = "./classes/MonthlyReports/" . $FileName; //$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel); //$objWriter->save($destination); $callEndTime = microtime(true); $callTime = $callEndTime - $callStartTime; echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; // Echo memory usage echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; $JustPeachey = str_replace('.php', '.xlsx', __FILE__); // Save Excel 95 file echo date('H:i:s') , " Write to Excel5 format" , EOL; $callStartTime = microtime(true); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); $objWriter->save(str_replace('.php', '.xls', __FILE__)); $callEndTime = microtime(true); $callTime = $callEndTime - $callStartTime; echo date('H:i:s') , " File written to " , str_replace('.php', '.xls', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; // Echo memory usage echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; // Echo memory peak usage echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; // Echo done echo date('H:i:s') , " Done writing files" , EOL; echo 'Files have been created in ' , getcwd() , EOL; $ch = curl_init(); $source = "http://localhost/classes/MonthlyReport.xlsx"; curl_setopt($ch, CURLOPT_URL, $source); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec ($ch); curl_close ($ch); $WriteFile = $_SESSION['FileName']; $file2 = fopen('/Users/tim/Sites/classes/MonthlyReports/' . $WriteFile, "w"); fputs($file2, $data); echo $System . '<br><br>'; }while($System !=''); die();

Where am I going wrong?

    I'm not sure, but I'm cringing at the while condition on your Do .. While loop.

      Considering that inspection of the while() condition and the loop's contents reveals that the do..while loop will either be executed once or an infinite number of times, I would say the symptoms sound like the script is running 'as designed' (i.e. you're in the "infinite" case). Whether or not you'll see incremental output from the echo statements would probably depend upon a number of factors (caching by the web server, caching by your browser, etc.).

      Using something like PuTTY or any other terminal-like program to connect directly to your webserver's listening port and manually executing an HTTP request would be one way to verify that something is indeed being sent to the client. However, if your webserver is buffering the data (either until some minimum size or, perhaps, indefinitely - i.e. to gzip/compress it all at the end), you might still not see any of the output.

        So, I changed the 'Do' loop to a 'for' loop. However, the problem still remains. localhost stalls at the beginning of the script. Once localhost wakens, and the 'for' loop kicks in, the script cooks. Now, the problem seems to be a nagging annoyance.

          I know what came over me to mark this thread as solved. Now, I'm waiting on localhost on many of the scripts I am trying to run. Also, one script that has 75 iterations will run for a few turns then hangs seemingly forever, then goes on through another batch of code and sits. Is there a cache file someI'm missing? (I have disabled Safari's cache and clean out Chrome's regularly). Any ideas?

            Write a Reply...