I am optimizing a php script for fast performance. The php script read 75 text file line by line and check a line exists in string and do rest
It is a HTTP API script which is called 1000 times per second.
I am creating a function to do this in the api.php script
function searchFile($data, $path)
{
$result=false;
if(file_exists($path))
{
$data_array= explode("\n", file_get_contents($path));
foreach($data_array as $data_value)
{
if(str_replace(' ', '', $data_value) != '')
{
if(stripos($data, $data_value) !== false)
{
$result = true;
file_put_contents('log.txt', $data.': '.$path.PHP_EOL, FILE_APPEND);
break ;
}
}
}
}
return $result;
}
$path_array[1]=.......
$path_array[2]=.......
---
$path_array[75]=.......
$data=..
foreach($path_array as $path)
{
if(searchFile($data, $path))
{
// do rest
}
}
My Questions..
1) The file size of each file max 500KB, so I use file_get_contents to read fast inserted fopen, fgets,
-- AM I CORRECT?
2) Each file has about 20000 lines. D0 I NEED TO USE unset($data_array) INSIDE FUNCTION FOR BETTER PERFORMANCE?
unset($data_array);
Thank you in advance