Jump to content

New WAMP Feature: Breaks after less than 200 loops


scheda

Recommended Posts

Okay, so I keep crashing my server while trying to get a simple script to run.

 

Firstly, here's the code.

 

<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');
$dbname = 'businessletters';
mysql_select_db($dbname);

$files = getFiles("parseme.txt");

for($i=0;$i<200;$i++) {
	$file = getReadFile($files[$i][0]);
	insertIntoDb($files[$i][1], $file);
	//echo "Inserted successfully - " . $files[$i][0] . "<br />";
}

function getFiles($file) {
	$fh = fopen($file, "rb");
	$data = fread($fh, filesize($file));
	fclose($fh);

	$dataArr = explode("\n", $data);

	for($i=0;$i<count($dataArr);$i++) {
		$dataArr[$i] = explode(",", $dataArr[$i]);
	}
	return($dataArr);
}

function getReadFile($file) {
	$fh = fopen($file, "rb");
	$data = fread($fh, filesize($file));
	fclose($fh);
	return $data;
}

function insertIntoDb($title, $body) {
	$sql = "insert into letters values('', '".mysql_real_escape_string($title)."', '".mysql_real_escape_string($body)."')\n";
	//mysql_query($sql) or die("Error inserting");
	echo $sql;
}

mysql_close();

?>

 

And now, here's what it's supposed to do.

 

Open and read File A - this file has file names and titles in a CSV file. File,Title is the format.

 

Then the loop starts. Here I would like to do everything in one run, which could be done by counting the records in the CSV file, which I can do with count(), but even 200 is too much. I have 600.

 

Anyway, it goes through the CSV file and opens every file referenced and pulls out the content.

 

Then it creates a simple SQL statement where the content is entered into the database.

 

And the problem is that Apache keeps crashing on me... There must be a better way for me to do this without having my server crash on me!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.