Hi,

I have built an automated system, but one of my scripts, infact one of the scripts near the front of my automated system is doing something that it is causing apache to throw up errors at times. Could someone please take alook at the following script, to see what could be causing this and see what could be done to improve the script.

The following script reads csv datafeed files and uses str_replace and then rewrites the data into a .txt file. The only problem is that this script is causing apache to stop/crash or something, which means this script doesn't then complete it's task and I have half completed .txt files.

PHP Code:
<?php
include ("./main/computerconnect.php");
$viewss file("00000convert.txt");
$views $viewss[0]; $views++;
$fp fopen("00000convert.txt""w");
fwrite($fp$views);
fclose($fp);
print 
"Now processing record <font color=red>$views</font>";
?><html><head><meta http-equiv="refresh" content="3"></head><body><?php
$sqlact 
mysql_query("select csvfilename, filename from prodseupload order by id asc limit $views, 1");
$listact mysql_num_rows($sqlact);
{
while (
$iact $listact) {$linesactmysql_fetch_array($sqlact);
$csvfile $linesact["csvfilename"];
$filenamecopy $linesact["filename"];
$iact++;}}
echo 
" - <i>Convert Filename: $csvfilename.txt</i><br /><br />";
$source_file "C:\phpdev\www\produpload\csvfiles\/$filenamecopy\/$csvfile.csv";
$dest_file "C:\phpdev\www\produpload\convert\/$filenamecopy.txt";
$row 1;
$source fopen($source_file"r");
if (
false == $source)
{

   die(
'could not open file ' $source_file ' for reading. Quitting');
}
$dest fopen($dest_file"w");
if (
false == $dest)
{
   
fclose($source);
   die(
'could not open file ' $dest_file ' for writing. Quitting');
}
while (
$data fgetcsv($source1000","))
{
   
$num count($data);
   echo 
'' $num ' fields in line . ' $row '<br />';
   
$row++;
   
$newRow implode(''$data) . "\n";
    
$newRow str_replace(',"'","$newRow);
    
$newRow str_replace('"'"&quot;"$newRow);
    
$newRow str_replace("&quot;&quot;""&quot;"$newRow);
    
$newRow str_replace("'""'"$newRow);
    
fwrite($dest$newRow);
}
fclose($dest);
fclose($source); 
?>
Could someone please help.

Thanks!