lock file between C and php -
although title mentions file, doesn't have file. locking mechanism do.
here situation: have daemon process written in c, , web page in php. i'd have way of mutual locking under situation, c daemon lock file , php detects situation , tells client side system busy.
is there easy way of doing this?
thanks,
flock
properly.
in php script, use non-blocking lock:
$fd = fopen('/var/run/lock.file', 'r+'); if (!flock($fd, lock_sh | lock_nb, $wouldblock) && $wouldblock) { // buzy }
the lock_nb flag make call non blocking. if file locked exclusively, return immediately. multiple pages allowed lock file @ same time.
you can release lock with
flock($fd, lock_un);
in c daemon, use blocking , exclusive lock:
flock(fd, lock_ex); // wait until no page has locked file
Comments
Post a Comment