I am trying to create a text file by reading data from a MS SQL database. Some files will have 600,000 or so lines. I want to initiate this through a browser. The browser is timing out, and the files are not complete. Here is the basic code I'm using.
Code:
$link = mssql_connect($server, '$user', '$pass');
mssql_select_db($db, $link);
$sql = "
select distinct number
from numlist num
join areacodes ar on ar.areacode = LEFT(num.number, 3)
where state = 'alabama'
";
$res = mssql_query($sql,$link);
set_time_limit(0);
ini_set('max_execution_time', 0);
$myFile = "alabama.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
while ($row = mssql_fetch_array($res)) {
$stringData = "@" . $row['number'] . "@@F211" . $row['number'] . "@@F299@\n";
fwrite($fh, $stringData);
}
fclose($fh);
echo "The list has been created.";
Any ideas on how to keep the browser from timing out and or getting the files to complete with all the data. Once the browser times out, the script stops writing to the file.
The upload_max_filesize is 50M. The file sizes are not all that large considering there is not a lot to each record, so I don't think the max filesize is an issue.
Am I barking up the wrong tree using a browser?
Any ideas would be appreciated.
tia...mike