daisy
daisy

Reputation: 23489

Is it possible to load an extension from PHP cli interface, without modify the ini file?

I checked man php and output of php -h, but I didn't seem to find such thing.

But I remember seeing it somewhere, you could do something like php -Xabc.so script.php to load an extension temporarily.

Anyone know that?

Upvotes: 16

Views: 16018

Answers (3)

kenorb
kenorb

Reputation: 166319

To disable all by default (by ignoring php.ini) and specify specific PHP extensions, try:

php -n $(for e in curl ctype json iconv; { echo -dextension=$e.so; } | xargs) -m

To run the script, change -m into file name.

Upvotes: 0

Ja͢ck
Ja͢ck

Reputation: 173522

Loading a regular extension via CLI is done with:

php -dextension=abc.so myfile.php

If your extension is not in the default path you can provide an absolute path as well:

php -dextension=/path/to/abc.so myfile.php

To load a Zend extension, it'd advisable to always pass an absolute path:

php -dzend_extension=/path/to/abc.so myfile.php

Upvotes: 31

zerkms
zerkms

Reputation: 254886

http://php.net/manual/en/features.commandline.options.php

 -z <file>        Load Zend extension <file>.

Found it by googling for "php cli load extension"

Upvotes: 2

Related Questions