GetDotted Domains

Viewing Thread:
"PHP File Access"

The "Freeola Customer Forum" forum, which includes Retro Game Reviews, has been archived and is now read-only. You cannot post here or create a new thread or review on this forum.

Mon 18/07/05 at 19:03
Regular
"with a blunt knife"
Posts: 456
I'm currently putting the finishing touches to a site. However some of the scripts access a file (and write to it every once in a while) and when a few users are on at the same time there seems to be a clash as they try to access and write at the same time. I tried to fix this by writing a WaitForFile function that would wait until it could read the file and then Flock it and only return when it had succeeded. However there still seems to be the problem. Any ideas?
Mon 18/07/05 at 22:51
Regular
"with a blunt knife"
Posts: 456
The file permissions are fine, it writes and reads successfully most of the time.

It's basically a log file. I probably could do it using a database but I would really prefer not to. I was just wondering if there was any normal way of opening a file so that one user can use it at a time and waits for the file to be freed up. The function I wrote to get a handle of a file for writing is as such:

function waitforfilehandle_write($path)
{
//echo "$path
\n";
$RetVal = -1;
if (file_exists($path))
{
$success = 0;
while ($success==0)
{
if (is_writable($path))
{
$handle = @fopen($path, 'w');
if ($handle && flock($handle,LOCK_EX))
{
$RetVal = $handle;
$success = 1;
}
else
{
fclose($handle);
}
}
}
}
else
{
echo "ERROR 908 - WaitForFileHandle_Write has no file";
}
return $RetVal;
}
Mon 18/07/05 at 22:02
Regular
"Pouch Ape"
Posts: 14,499
Sounds like a permissions issue. Look up CHMOD 0777 - change mode. 0777 Has all permissions open for writing. You can also right-click the file and tick the boxes to set the mode of the file, if it allows.
Mon 18/07/05 at 20:20
Regular
Posts: 10,364
Hmmm.

When you say "write to a file", what exactly is being written?

You could probably do with a database instead...
Mon 18/07/05 at 19:03
Regular
"with a blunt knife"
Posts: 456
I'm currently putting the finishing touches to a site. However some of the scripts access a file (and write to it every once in a while) and when a few users are on at the same time there seems to be a clash as they try to access and write at the same time. I tried to fix this by writing a WaitForFile function that would wait until it could read the file and then Flock it and only return when it had succeeded. However there still seems to be the problem. Any ideas?

Freeola & GetDotted are rated 5 Stars

Check out some of our customer reviews below:

Wonderful...
... and so easy-to-use even for a technophobe like me. I had my website up in a couple of hours. Thank you.
Vivien
Second to none...
So far the services you provide are second to none. Keep up the good work.
Andy

View More Reviews

Need some help? Give us a call on 01376 55 60 60

Go to Support Centre
Feedback Close Feedback

It appears you are using an old browser, as such, some parts of the Freeola and Getdotted site will not work as intended. Using the latest version of your browser, or another browser such as Google Chrome, Mozilla Firefox, or Opera will provide a better, safer browsing experience for you.