scriptotek / php-marc

Simple interface for working with MARC records using the File_MARC package
MIT License
51 stars 11 forks source link

XMLWriter not found #14

Closed welblaud closed 5 years ago

welblaud commented 5 years ago

I have just installed php-marc via composer but when I try to use it, it logs:

PHP Fatal error:  Uncaught Error: Class 'XMLWriter' not found in /home/user/project_test/vendor/pear/file_marc/File/MARCBASE.php:95

The installation process went well, I tried to regenerate autoloading but nothing helped.

The example I am trying to use:

    require __DIR__. '/vendor/autoload.php';

    use Scriptotek\Marc\Collection;

    $collection = Collection::fromFile('./tmp/exportvuf.mrc');
    foreach ($collection as $record) {
        echo $record->getField('001')->getData() . "\n";
    }

PHP 7.2.19 Composer 1.9.0 Ubuntu 19.04

danmichaelo commented 5 years ago

Seems like your're missing the xmlwriter extension. It's often included by default when you install PHP, but clearly not in your case. Try installing php-xml (https://askubuntu.com/a/1044660)

welblaud commented 5 years ago

@danmichaelo, that was my very first attempt to make it to work.

I have php7.2-xml installed.

php -i | grep "xml" returns:

xmlrpc_error_number => 0 => 0
xmlrpc_errors => Off => Off
libxml

From the askubuntu thread, I am not sure what it should return in the case php-xml is ready. Or should I enable it or so?

danmichaelo commented 5 years ago

Hm, seems like xmlwriter is a separate extension, but it got installed by default for me. Here's what I got (on Red Hat):

php -i | grep -i "xml"
/etc/opt/rh/rh-php72/php.d/20-simplexml.ini,
/etc/opt/rh/rh-php72/php.d/20-xml.ini,
/etc/opt/rh/rh-php72/php.d/20-xmlwriter.ini,
/etc/opt/rh/rh-php72/php.d/30-xmlreader.ini
xmlrpc_error_number => 0 => 0
xmlrpc_errors => Off => Off
DOM/XML => enabled
DOM/XML API Version => 20031129
libxml Version => 2.9.1
libxml
libXML support => active
libXML Compiled Version => 2.9.1
libXML Loaded Version => 20901
libXML streams => enabled
mbstring.http_output_conv_mimetypes => ^(text/|application/xhtml\+xml) => ^(text/|application/xhtml\+xml)
SimpleXML
Simplexml support => enabled
xml
XML Support => active
XML Namespace Support => active
libxml2 Version => 2.9.1
xmlreader
XMLReader => enabled
xmlwriter
XMLWriter => enabled
libxslt compiled against libxml Version => 2.9.1

The XMLWriter => enabled line shows that the xmlwriter extension is enabled.

Perhaps there's a php7.2-xmlwriter package?

welblaud commented 5 years ago

I omitted the -i argument for grep:

xmlrpc_error_number => 0 => 0
xmlrpc_errors => Off => Off
libxml
libXML support => active
libXML Compiled Version => 2.9.4
libXML Loaded Version => 20904
libXML streams => enabled
danmichaelo commented 5 years ago

Yeah, I did that at first too. But indeed seems like you're missing some php extensions. Try installing php7.2-xmlwriter. You might also need php7.2-dom and php7.2-simplexml, not sure.

welblaud commented 5 years ago

In Ubuntu, it seems apt has php7.2-xmlwriter and php7.2-xml associated to php7.2-xml.

In the PHP Manual, there is:

The XMLWriter extension was initially a PECL extension for PHP 5. It was later added to the PHP source (bundled) as of PHP 5.1.2. This extension is enabled by default.

This could be the problem why I don't see any configs, modules or extensions. I guess it should work without any additional configuration.

Strange.

danmichaelo commented 5 years ago

Hm, yeah, it should be enabled by default. How did you install php?

welblaud commented 5 years ago

@danmichaelo, really simply, via apt :)

danmichaelo commented 5 years ago

In that case it should be enough with

apt install php php-xml

On a fresh Ubuntu 19 virtual machine I then get the following,

$ php -i | grep -i xml
/etc/php/7.2/cli/conf.d/15-xml.ini,
/etc/php/7.2/cli/conf.d/20-simplexml.ini,
/etc/php/7.2/cli/conf.d/20-xmlreader.ini,
/etc/php/7.2/cli/conf.d/20-xmlwriter.ini,
xmlrpc_error_number => 0 => 0
xmlrpc_errors => Off => Off
DOM/XML => enabled
DOM/XML API Version => 20031129
libxml Version => 2.9.4
libxml
libXML support => active
libXML Compiled Version => 2.9.4
libXML Loaded Version => 20904
libXML streams => enabled
SimpleXML
Simplexml support => enabled
xml
XML Support => active
XML Namespace Support => active
libxml2 Version => 2.9.4
xmlreader
XMLReader => enabled
xmlwriter
XMLWriter => enabled
libxslt compiled against libxml Version => 2.9.4

If you do not get XMLWriter => enabled at this point, the must be something odd with your setup.

welblaud commented 5 years ago

It somehow helped to reinstall the whole php, (php-common, php-cli, php-xml). Now it logs:

/etc/php/7.2/cli/conf.d/15-xml.ini,
/etc/php/7.2/cli/conf.d/20-simplexml.ini,
/etc/php/7.2/cli/conf.d/20-xmlreader.ini,
/etc/php/7.2/cli/conf.d/20-xmlwriter.ini,
xmlrpc_error_number => 0 => 0
xmlrpc_errors => Off => Off
DOM/XML => enabled
DOM/XML API Version => 20031129
libxml Version => 2.9.4
libxml
libXML support => active
libXML Compiled Version => 2.9.4
libXML Loaded Version => 20904
libXML streams => enabled
SimpleXML
Simplexml support => enabled
xml
XML Support => active
XML Namespace Support => active
libxml2 Version => 2.9.4
xmlreader
XMLReader => enabled
xmlwriter
XMLWriter => enabled
libxslt compiled against libxml Version => 2.9.4

Closing the issue.