How to install a PECL package with composer?

Viewed 3379

I wish to install a PEAR package (specifically, the mongodb from pecl.php.net) with Composer.

I can install a package from the main 'pear' channel with the following composer.json:

{ "repositories": [{
            "type": "pear",
            "url": "https://pear.php.net"
        }],
    "require": { "pear-pear/http": "*" }
}

(note: an original example from https://getcomposer.org/doc/05-repositories.md#pear is not working)

But I'm getting:

The requested package pear-pecl/mongodb could not be found in any version, there may be a typo in the package name

...when I try to set 'pecl' channel:

"require": { "pear-pecl/mongodb": "*" }

I can see the pecl channel with pear list-channels:

$ pear list-channels
Registered Channels:
====================
Channel      Alias   Summary
doc.php.net  phpdocs PHP Documentation team
pear.php.net pear    PHP Extension and Application
                     Repository
pecl.php.net pecl    PHP Extension Community Library

I can install the same package with pear install pecl/mongodb.

2 Answers

pecl/mongodb is a binary driver. I can't see how composer could be able to install it locally to a project. I don't think you'll be able to install any PECL extension through composer.

Composer can manage PHP dependencies for a project, and those dependencies need to include a valid composer.json file to be able to be identified as a package.

If you check the pecl/mongodb repo, you'll see no such thing. It's a C language project that needs to be compiled and installed as runtime extension.

PECL extensions are not meant to installed on a project, nor makes sense to do so; but need to installed and enabled for the PHP runtime. When you run pear install pecl/mongodb you are installing the binary extension for all projects using the same runtime.

Related