Getting a file pointer from file descriptor
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?
精彩评论