this is (as usual) totally untested and i make no claims of "fitness for a purpose" yatta yatta, however, this should go thru a conf file "foo" and, if the line "timeout=60" is encountered, change it to "timeout="30"... you can of course use the popular "else" command to make it toggle back to 60 on a second pass...
the flow is:
1) open file for reading
2) lock it
3) read the whole file into the array $write_line, making changes to said file as is defined in the if statement(s)
4) close and unlock
5) the same file for writing and, of course, lock it
6) write the whole array in there
7) unlock and close
if this is what you are looking for, i would suggest adding error detection on the flock calls. also check out the flock() function to see if you want to implement any of its features (ie blocking, testing fer timeouts on waiting for the file to release &c). if this is not what yer talking about... well, oops.
$fp = fopen('/path/to/foo', 'r');
flock($fp,1); // 1 locks for reading
while (!feof ($fp))
{
$line = fgets($fp, 4096); // read ONE line or 4096 chars, whichever comes first.
if((strstr($line, "timeout")) && (strstr($line, "60")))
$write_line[] = "timeout=30";
else
$write_line[] = $line;
}
fclose($fp);
flock($fp, 3); // 3 releases lock
$fp = fopen('/path/to/foo', 'w');
flock($fp,1);
for($i=0;$i<count($write_line);$i++)
fwrite($fp, $write_line[$i]);
fclose($fp);
flock($fp, 3);
-frymaster