optimal way to prepend a file in php
Prepend a string to a file in php
- Size of file can be very large.
- Need an optimal solution while keeping performance as the key factor.
This is what i have so far
function prepend($string, $filename) {
$context = stream_context_create ();
$fp = fopen($filename,'r',1,$context);
$tmpnam开发者_如何学Ce = md5($string);
file_put_contents($tmpname,$string);
file_put_contents($tmpname,$fp,FILE_APPEND);
fclose($fp);
unlink($filename);
rename($tmpname,$filename);
}
精彩评论