php8.5
Home/ Manual/ gnupg / functions/ gnupg_init

gnupg_init

PHP function Edit on GitHub ✎

(PECL gnupg >= 0.4)

Initialize a connection

Description

gnupg_init(array|null $options = null): resource

Parameters

options

Must be an associative array. It is used to change the default configuration of the crypto engine.

keytypedescription
file_namestringIt is the file name of the executable program implementing this protocol which is usually path of the gpg executable.
home_dirstringIt is the directory name of the configuration directory. It also overrides GNUPGHOME environment variable that is used for the same purpose.

Return Values

A GnuPG resource connection used by other GnuPG functions.

Changelog

VersionDescription
PECL gnupg 1.5.0The options parameter was added.

Examples

Procedural gnupg_init() example with default setting

php
<?php
$res = gnupg_init();
?>

Procedural gnupg_init() example with overridden file name and home dir

php
<?php
$res = gnupg_init(["file_name" => "/usr/bin/gpg2", "home_dir" => "/var/www/.gnupg"]);
?>

OO gnupg initializer example with default setting

php
<?php
$gpg = new gnupg();
?>

OO gnupg initializer example with overridden file name and home dir

php
<?php
$gpg = new gnupg(["file_name" => "/usr/bin/gpg2", "home_dir" => "/var/www/.gnupg"]);
?>

Source: reference/gnupg/functions/gnupg-init.xml · from the official PHP manual (php/doc-en)