Hey!
ok i always use text databases for all my scripts but i see they changed the code for file locking for PHP4 so i need to know if what i'm doing would work in PHP4 and if i am even doing it right in the first place lol...
right now this is how i do my file locking for reading and writing
$fp = fopen($reset_log_file, "w");
flock($fp,2);
$fw = fwrite($fp, $reset_date);
fclose($fp);
and
$fp = fopen($site_log_file, "r");
flock($fp,1);
$reset_list = fread($fp, filesize($site_log_file));
fclose($fp);
that's from a top site list script i wrote
see that here if you're curious http://rpggateway.com/rpg100/
now i'm wondering ok i lick the file for writing, but doesn't that mean it can still be read? and i don't need file locking on when i'm totaly re-writing the file "w or w+" right?
and with PHP4 would the numbers work? i saw on this one scripts code they did this and is this what i should do so file locking would work with both 3 and 4?
$LOCK_EX = 2;
$LOCK_UN = 3;
$text = implode("\n",$newlines);
$fp = fopen($logfile,"w");
flock($fp,$LOCK_EX);
fwrite($fp,$text);
flock($fp,$LOCK_UN);
fclose($fp);
one thing i don't understand... i thought the file locking was automaticly taken off when the file closes so why end it manualy?
if somone can give me details on this it would be very much helpful because i don't want any of my databases to get screwed up 🙂
Thanks
~Blake