我想在使用 open 打开文件时获取返回资源的系统文件描述符。我假设描述符是一个 INT 值,通常在/dev/fd/
我知道我可以通过执行以下操作来读取描述符:
fread("php://fd/$descriptor", $buflen);
但现在我想获取由 PHP 的 fopen
() 打开的资源的描述符。有办法吗?
最佳答案
这是一种相当 hacky 的解决方法,但它确实有效!
function fd($realpath) {
$dir = '/proc/self/fd/';
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
$filename = $dir . $file;
if (filetype($filename) == 'link' && realpath($filename) == $realpath) {
closedir($dh);
return $file;
}
}
closedir($dh);
}
return FALSE;
}
关于php - fopen 并获取系统文件描述符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5600811/