Ideally, the process shouldn't stop and continue going on. If you are using PHP 5, you should be able to take advantage of exceptions. If you aren't, then to me error/return values aren't being checked appropriately.
mysql connect
mysql select database table
mysqlquery get all companies
mysql fetch {
pull out data items
assemble them
pass off to PDF converter to generate file
}
mysql close
At each stage, you must check to see if an error occurred. If there was an error, report it and then move to the next record. If it is crapping out, you will need to trace what's going on with debugging statements.
Here's a simple debug class that you can use to insert into the application and store output at different execution points in the program. This way you can capture the thread of execution and then debug to help pinpoint where it is crapping out:
class DebugFile {
var $output;
function DebugFile() {
$this->output = "";
}
function AddLine($str) {
$this->output .= date("F d Y H:i:s", time()) . " " . $str . "\n";
}
function Save() {
file_put_contents("debug.txt", $this->output, FILE_APPEND | FILE_TEXT | FILE_EX);
}
function Show() {
echo $this->output;
}
function ShowHtml() {
echo nl2br($this->output);
}
}
?>
For example (pseudo code), I imagine the application has some sort of algorithm structure similar to that below. You could do the following in the main heart of the program:
$dbg = new DebugFile();
mysql connect
mysql select database table
mysqlquery get all companies
mysql fetch each company {
$companyName = $data['company'];
$dbg->AddLine("Execution point 1: " . $companyName . "\n");
$dbg->Save(); // just in case it craps out before
pull out data items from record
$dbg->AddLine("Execution point 2: " . $companyName . "\n");
$dbg->Save(); // just in case it craps out before
assemble them to form document
$dbg->AddLine("Execution point 3: " . $companyName . "\n");
$dbg->Save(); // just in case it craps out before
pass off document string to PDF converter to generate file
$dbg->AddLine("Execution point 4: " . $companyName . "\n");
$dbg->Save(); // just in case it craps out before
}
mysql close
$dbg->ShowHtml();