1.
$fname = "blah.ext";
$fp = fopen($fname,"w+") or die("Unable to open");
$data = fread($fp,filesize($fnam));
2.flock($fp,2) or die("Unable to lock");
3. $data = substr($data,0,4)."pqrst".substr($data,4);
4. $fwrite($fp,$data) or die("Unable to write");
5. $flock($fp,3) or die("Unable to release");
6. $fclose($fp) or die("Unable to close");
Please check the filesystem compatibility for flock functionality.
Hope this helps, good luck