问题描述
在与PHP源代码进行了半小时的搏斗之后,我放弃了. :P问题是-在Gentoo Linux系统上,PHP flock()函数调用可以归结为哪个系统调用?我遇到了一些问题(例如在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.
推荐答案
// example: $stream = fopen(FILE, 'rb') or die('???');
$md = stream_get_meta_data($stream);
echo $md['wrapper_type'];
flock($stream);
如果打印出 plainfile ,则对php函数flock()的调用由php_stdiop_set_option(...)处理.该调用flock().取决于PHP是否使用HAVE_FLOCK编译,这可能是系统调用 flock()或flock_compat.c中定义的使用 fcntl().在我的gentoo系统上,PHP是使用HAVE_FLOCK编译的.
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(...):
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;
这篇关于PHP flock()-底层是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!