0

i have a big text file and (20m line) when i try to use this code i see handle error. http error code is 500. and that is my code :

<?php
$_SESSION['id'] = $_GET['id'];
ini_set('memory_limit', '-1');
$file = 'myfile.txt';
error_reporting(0);
ini_set('display_errors', 0);
//echo $_SESSION["id"];
$searchfor = $_SESSION["id"];

// the following line prevents the browser from parsing this as HTML.
header('Content-Type: text/plain');

// get the file contents, assuming the file to be readable (and exist)
$contents = file_get_contents($file);
// escape special characters in the query
$pattern = preg_quote($searchfor, '/');
// finalise the regular expression, matching the whole line
$pattern = "/^.*$pattern.*\$/m";
// search, and store all matching occurences in $matches
if(preg_match_all($pattern, $contents, $matches)){
   echo implode("\n", $matches[0]);
}
else{
   echo "No matches found";
}

what i should do to dont get error any more ?and make my search code faster?!should i split my text and do multithread serach? how i do this? (sorry for my bad english language grammer)

0 Answers0