A
A
Alexey Tolstoukhov2018-03-25 08:29:29
PHP
Alexey Tolstoukhov, 2018-03-25 08:29:29

Working with large files for preg_match_all?

$base = file_get_contents("https://site.ru/base.php"); // base.php используется как txt файл.
$text = "Поиск";
preg_match_all('/\b'.$text.'\:(.*)/i', $base, $otvet);

The base exceeds more than 2 million lines, after the request it does not display anything.
What to do? fopen tried the same...

Answer the question

In order to leave comments, you need to log in

3 answer(s)
O
Oleg, 2018-03-25
@402d

look at the file size. let it be 8 meters
file_get_contents(" https://site.ru/base.php "); - 8+
$base = 16m allocated
for the pre-match is also an overhead.
so try to give the scripts 4 file sizes. available memory

K
ksnk, 2018-03-25
@ksnk

file_get_contents reads into memory. No memory - no cookies, look in the error logs... Try to read in the fopen-fread loop not the whole file, but in pieces of 64k, for example. The only problem is not to lose the possible "tail", for example, by throwing the last 5 characters from the previous reading to the beginning of the next one.

P
pantsarny, 2018-03-26
@pantsarny

give an example of lines from a file, and the size of the file

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question