PHP flock() - 幕后有什么?

发布于 2024-07-24 22:06:57 字数 147 浏览 9 评论 0原文

在与 PHP 源码搏斗了半个小时后,我放弃了。 :P 问题是 - 在 Gentoo Linux 系统上,PHP freeze() 函数调用归结为什么系统调用? 我遇到了一些问题(例如在每一个20个循环迭代中阻塞30秒之类的问题),我想知道为什么会这样是这样。

After wrestling with PHP source for a half an hour, I gave up. :P The question is - what system call does the PHP flock() function call boil down to on a Gentoo Linux system? I'm having some issues with it (like block-for-30-seconds-in-every-one-of-20-loop-iterations kind of issues) and I would like to know why that is so.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

挽清梦 2024-07-31 22:06:57
// example: $stream = fopen(FILE, 'rb') or die('???');
$md = stream_get_meta_data($stream);
echo $md['wrapper_type'];
flock($stream);

if this prints plainfile then the call to the php function flock() is handled by php_stdiop_set_option(...) which calls flock(). Depending on whether PHP was compiled with HAVE_FLOCK or not this may be the system call flock() or a function defined in flock_compat.c which utilizes fcntl(). On my gentoo system PHP was compiled with HAVE_FLOCK.

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

 案例 PHP_STREAM_OPTION_LOCKING: 
              如果(fd==-1){ 
                  返回-1; 
              } 

              if ((zend_uintptr_t) ptrparam == PHP_STREAM_LOCK_SUPPORTED) { 
                  返回0; 
              } 

              if (!flock(fd, 值)) { 
                  数据->lock_flag = 值; 
                  返回0; 
              } 别的 { 
                  返回-1; 
              } 
              中断;

// example: $stream = fopen(FILE, 'rb') or die('???');
$md = stream_get_meta_data($stream);
echo $md['wrapper_type'];
flock($stream);

if this prints plainfile then the call to the php function flock() is handled by php_stdiop_set_option(...) which calls flock(). Depending on whether PHP was compiled with HAVE_FLOCK or not this may be the system call flock() or a function defined in flock_compat.c which utilizes fcntl(). On my gentoo system 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;
浅笑依然 2024-07-31 22:06:57

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);

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);
寒江雪… 2024-07-31 22:06:57

除非我误解了你的要求,否则 PHP 的 flock() 是对 Unix 系统函数 flock() 在 Gentoo 上。 它们具有相同的语义。

Unless I'm misunderstanding what you're asking, PHP's flock() is a call to the Unix system function flock() on Gentoo. They have identical semantics.

夏天碎花小短裙 2024-07-31 22:06:57

您是否在联网或已安装的驱动器上使用它? 如果您遇到的是死锁,以及一些文档中的评论讨论了这一点。

flock 的文档

Are you using it on a networked or mounted drive? I wouldn't be surprised if what you are experiencing is deadlock, and some of the comments in the documentation talk about that.

The documentation for flock.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文