> soal flock(), setahu saya itu mah mesti di unix mas, so kalo offline
> emang
> ngga bisa. tapi berdasarkan pengalaman dan UUD 45, masalah flock()
> itu bisa
> diatasi dengan men-disable sementara flock()-nya
===
Untuk sistem operasi Windows, yang bisa hanya Windows NT...Windows 95
s/d 98 nggak bisa semua....jadi bukan cuman unix aja mas...:)
Selain men-disable flock(), bisa juga di bikin suatu function yang
mirip flock...jadi aplikasi itu bisa dijalankan di windows maupun di
unix...berikut ini adalah function lock & unlocknya..
#######################################################################
# get_file_lock #
#######################################################################
# get_file_lock is a subroutine used to create a
lockfile.
# Lockfiles are used to make sure that no more than one
# instance of the script can modify a file at one time.
A
# lock file is vital to the integrity of your data.
# Imagine what would happen if two or three people
# were using the same script to modify a shared file
(like
# the error log) and each accessed the file at the same
# time. At best, the data entered by some of the users
# would be lost. Worse, the conflicting demands could
# possibly result in the corruption of the file.
#
# Thus, it is crucial to provide a way to monitor and
# control access to the file. This is the goal of the
# lock file routines. When an instance of this script
# tries to access a shared file, it must first check
for
# the existence of a lock file by using the file lock
# checks in get_file_lock.
#
# If get_file_lock determines that there is an existing
# lock file, it instructs the instance that called it
to
# wait until the lock file disappears. The script then
# waits and checks back after some time interval. If
the
# lock file still remains, it continues to wait until
some
# point at which the admin has given it permissions to
just
# overwrite the file because some other error must have
# occurred.
#
# If, on the other hand, the lock file has disappeared,
# the script asks get_file_lock to create a new lock
file
# and then goes ahead and edits the file.
#
# The subroutine takes one argument, the name to use
for
# the lock file and is called with the following
syntax:
#
# &get_file_lock("file.name");
sub get_file_lock
{
local ($lock_file) = @_;
local ($endtime);
$endtime = 20;
$endtime = time + $endtime;
# We set endtime to wait 20 seconds. If the lockfile
has
# not been removed by then, there must be some other
# problem with the file system. Perhaps an instance of
# the script crashed and never could delete the lock
file.
while (-e $lock_file && time < $endtime)
{
sleep(1);
}
open(LOCK_FILE, ">$lock_file") || &file_open_error ("$lock_file",
"Lock File
Routine",
__FILE__,
__LINE__);
# Note: If flock is available on your system, feel free
to
# use it. flock is an even safer method of locking
your
# file because it locks it at the system level. The
above
# routine is "pretty good" and it will server for most
# systems. But if you are lucky enough to have a
server
# with flock routines built in, go ahead and uncomment
# the next line and comment the one above.
# flock(LOCK_FILE, 2); # 2 exclusively locks the file
}
#######################################################################
# release_file_lock #
#######################################################################
# release_file_lock is the partner of get_file_lock.
When
# an instance of this script is done using the file it
# needs to manipulate, it calls release_file_lock to
# delete the lock file that it put in place so that
other
# instances of the script can get to the shared file.
It
# takes one argument, the name of the lock file, and is
# called with the following syntax:
#
# &release_file_lock("file.name");
sub release_file_lock
{
local ($lock_file) = @_;
# flock(LOCK_FILE, 8); # 8 unlocks the file
# As we mentioned in the discussion of get_file_lock,
# flock is a superior file locking system. If your
system
# has it, go ahead and use it instead of the hand
rolled
# version here. Uncomment the above line and comment
the
# two that follow.
close(LOCK_FILE);
unlink($lock_file);
}
__________________________________________________
Do You Yahoo!?
Yahoo! Shopping - Thousands of Stores. Millions of Products.
http://shopping.yahoo.com/
Analisa Web Berhadiah total Rp.500.000 + Tshirt & Topi :
http://www.master.web.id/cgi-bin/webkritik/oktober.cgi
-------[ Master Web Indonesia - www.master.web.id ] -------
Moderator : [EMAIL PROTECTED]
Berlangganan : [EMAIL PROTECTED]
Stop Berlangganan : [EMAIL PROTECTED]
-----------------------------------------------------------