Do I need to use flock() when reading a file into an array? It's possible that
the file in question could be open at the time the file('filename' ) request is
made. I realize flock() is required when opening a file with fopen() when there
is contention for the file:
$fp=fopen($ctr, 'w');
//only write if we can get lock on file
if (flock($fp, LOCK_EX))
{
fwrite($fp, "0");
flock($fp, LOCK_UN);
}
else
{
//try again... how???????
}
fclose($fp);
but is it required when reading a file into an array?
$totals=file('v isinterval');
$var=explode('| ',$totals[0]);
$i24h = number_format($ var[0]);
$i30d = number_format($ var[1]);
$i365d = number_format($ var[2]);
also - if the attempt to get a lock on the file fails (in the first example),
how do I retry?
Thanks in advance.
the file in question could be open at the time the file('filename' ) request is
made. I realize flock() is required when opening a file with fopen() when there
is contention for the file:
$fp=fopen($ctr, 'w');
//only write if we can get lock on file
if (flock($fp, LOCK_EX))
{
fwrite($fp, "0");
flock($fp, LOCK_UN);
}
else
{
//try again... how???????
}
fclose($fp);
but is it required when reading a file into an array?
$totals=file('v isinterval');
$var=explode('| ',$totals[0]);
$i24h = number_format($ var[0]);
$i30d = number_format($ var[1]);
$i365d = number_format($ var[2]);
also - if the attempt to get a lock on the file fails (in the first example),
how do I retry?
Thanks in advance.
Comment