Hi I am relatively new to PHP and have had some success using php.net for a lot of my scripting, however I am having trouble with this script I am using. Basically I have a large number of files in a folder and a database table that logs the entries when I parse them through, which will also allow me to see which files need updating when they become available. What I have done is created a script that identifies and returns the files that are not included in the list, which works up to a point, but when this list becomes too large the script ceases to function properly.
Here is my code:
[code]<?php
// Database credentials
include(‘config.php’);
// Function to list the file names, seperated by a comma
function direktorylist ($direkt) {
$files = “”;
$filenomArray = array();
// Look for all xml files type ‘s’ and put them into an array
$result = mysql_query(“SELECT u_xml FROM filebank WHERE file_type = ‘s’”);
while($row = mysql_fetch_array($result)) {
array_push($filenomArray,$row[‘u_xml’]);
}
// Open directory, check to see if the file already exists on the database,
// if not return them in a comma seperated string
if ($handle = opendir($direkt)) {
$file_names = “”;
while (false !== ($file = readdir($handle))) {
if ($file != “.” && $file != “…”) {
$file = str_replace(".xml","",$file);
if (!in_array($file,$filenomArray,true)) {
$file_names .=$file.",";
}
}
}
// Remove the last comma
$file_names = substr($file_names,0,strlen($file_names)-1);
closedir($handle);
} else {
$file_names = “could not open directory {$direkt}”;
}
return $file_names;
}
// Fatal error: Maximum execution time exceeds… etc etc…
echo direktorylist(‘Folder1/’);
?>[/code]
I believe line 23 – “if (!in_array($file,$filenumArray,true))” is the culprit here, so what I am wondering is if there is a more efficient way to search arrays, do I need to make another loop, or a different array, or have I just gotten something horribly wrong?
Lucas.