使用系统调用在php中写入和读取文件是否合适?

I need to keep a 20k to 30k file register with a simple key:value per line. I need to keep it in a file , since other instance also will use it. Then I will need to find an especific key to get its value and also write a key:value in the file. I was wondering wich of the following methods are faster / better or considered as good practice.

In order to write to file, I know about three ways to do it: first:

$fh = fopen('myfile.txt', 'a') or die("can't open file");
fwrite($fh, 'key:value');
fclose($fh);

second or with file_put_contents

file_put_contents('myfile.txt','key:value',FILE_APPEND);

and third using a system call.

exec("echo key:value >> myfile.txt");

And also, in order to read a file and find a line a can do: Using file_get_contents

$filename = 'info.txt';
$contents = file_get_contents($filename);
foreach($contents as $line) {
$pos = strpos($line, $key);
}

Using file

$filename = 'info.txt';
$contents = file($filename);
foreach($contents as $line) {
$pos = strpos($line, $key);
}

And with a system call:

exec("grep $key | wc -l",$result);

I guess you already considered using a database? Because otherwise you are reinventing the wheel. A database has all the advantages with fast-seeking and row-level locking.

If you are using a file, you have to build this by yourself.

I strongly advice to switch to some kind of database.

BTW, you don't mention if you are replacing values or just appending to the file.