开发者

Getting a file pointer from file descriptor

开发者 https://www.devze.com 2022-12-26 18:33 出处:网络
In PHP 5.2.3, \"fdopen\" was used to read/write to a file descriptor that\'s open开发者_如何学Ced by another application.

In PHP 5.2.3, "fdopen" was used to read/write to a file descriptor that's open开发者_如何学Ced by another application.

fdopen(<fileDescriptorId>,"rw");  //It worked fine with PHP 5.2.3

After upgrading PHP to 5.3.2, it's throwing "undefined reference to 'fdopen' function".

Please suggest whats the replacement for this in PHP 5.3.2 or any workaround.


As of PHP 5.3.6 (and still valid and working with PHP 7.2.1), the proper method to access a file descriptor is to use fopen with php://fd:

$fd = 3;
$pipe = fopen("php://fd/{$fd}", 'w');
fwrite($pipe, 'hello!');


Could this fdopen() of yours have been provided by a custom php extension?
On a linux/unix server

function fdopen($id, $mode) {
  return fopen("/proc/self/fd/".(int)$id, $mode);
}

might work.

edit: see http://linux.die.net/man/5/proc


The fdopen is related to C language. There is no such function in PHP. I think you have mis-typed the PHP's fopen function, right?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号