OpenSwoole\Coroutine\PostgreSQL->openLOB(...)

Latest version: pecl install openswoole-26.11.1 | composer require openswoole/core:26.11.1

Declaration

<?php OpenSwoole\Coroutine\PostgreSQL->openLOB(int $oid, string $mode = "rb"): resource|false

Parameters

oid

The OID of the large object.

mode

Open mode. The default rb opens the object read only, a mode containing w or + (for example wb or r+b) opens it for reading and writing.

Return

Returns a PHP stream resource for the large object, or false on failure, check the error property.


Description

Open an existing large object and return it as a PHP stream. Use the normal stream functions such as fread(), fwrite(), fseek(), stream_get_contents() and fclose() on it.

Large object operations must run inside a transaction. Streams that are still open are closed when the transaction ends (after COMMIT or ROLLBACK).

A large object stream can be passed as a parameter to PostgreSQLStatement->execute(), its OID is sent as the parameter value.


Example

<?php

use OpenSwoole\Coroutine\PostgreSQL;

co::run(function()
{
    $pg = new PostgreSQL();
    $pg->connect("host=127.0.0.1 port=5432 dbname=test user=postgres password=***");

    $pg->query('BEGIN');

    $stmt = $pg->query('SELECT data FROM files WHERE id = 1');
    $oid = $stmt->fetchAssoc()['data'];

    $lob = $pg->openLOB($oid);
    var_dump(stream_get_contents($lob));
    fclose($lob);

    $pg->query('COMMIT');
});
Last updated on November 20, 2026