PHP flock () - what's under the hood?

After struggling with the PHP source for half an hour, I gave up .: P The question is, what system call calls the PHP flock () function call on the Gentoo Linux system? I had problems with it (for example, problems with blocks in 30 seconds in each of the 20 cycles), and I would like to know why this is so.

+6
php flock
Jun 16 '09 at 14:08
source share
4 answers

// example: $stream = fopen( FILE , 'rb') or die('???'); $md = stream_get_meta_data($stream); echo $md['wrapper_type']; 
flock($stream);
if it prints plainfile, then the php flock () function call is handled by php_stdiop_set_option (...), which calls flock (). Depending on whether PHP is compiled with HAVE_FLOCK or not, this may be a flock () system call or a function defined in flock_compat.c that uses fcntl () . On my system, gentoo PHP was compiled with HAVE_FLOCK.

main / streams / plain_wrapper.c @static int php_stdiop_set_option (...):

  case PHP_STREAM_OPTION_LOCKING:
             if (fd == -1) {
                 return -1;
             }

             if ((zend_uintptr_t) ptrparam == PHP_STREAM_LOCK_SUPPORTED) {
                 return 0;
             }

             if (! flock (fd, value)) {
                 data-> lock_flag = value;
                 return 0;
             } else {
                 return -1;
             }
             break; 
+3
Jun 16 '09 at 14:49
source share

http://www.opengroup.org/onlinepubs/009695399/functions/fcntl.html

 /etc/standard/flock_compat.c [line 66] ret = fcntl(fd, operation & LOCK_NB ? F_SETLK : F_SETLKW, &flck); 
+2
Jun 16 '09 at 15:00
source share

If I don’t understand what you are asking, PHP flock() is a call to the Gentoo Unix flock() system function. They have identical semantics.

0
Jun 16 '09 at 14:12
source share

Do you use it on a network or mounted drive? I would not be surprised if you experience deadlock , and some of the comments in the documentation say this.

Documentation for the pack .

0
Jun 16 '09 at 14:12
source share



All Articles