PostgreSql大对象通过PHP PDO提交

This code outputs LO to browser:

...
$my_pdo_connect->beginTransaction();
$stream = $my_pdo_connect->pgsqlLOBOpen($oid, 'r');
fpassthru($stream);
...

But I stuck with writing LO to file system. I am aware about pg_lo_export and lo_export, but there is
restriction to use PHP PDO capabilities only. Obviously I should use some php-function instead of fpassthru($stream) to write the stream into a file, can't find suitable docs or example.

Finally I found how to solve the issue:

$my_pdo_connect->beginTransaction();
$stream = $my_pdo_connect->pgsqlLOBOpen($oid, 'r');
$file = fopen('my_file', 'w');
stream_copy_to_stream($stream, $file);
fclose($file);