开发者

optimal way to prepend a file in php

开发者 https://www.devze.com 2023-01-07 02:52 出处:网络
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.

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); 
    } 
0

精彩评论

暂无评论...
验证码 换一张
取 消