What is the fastest XML parser in PHP?
The fastest parser will be SAX -- it doesn't have to create a dom, and it can be done with partial xml, or progressively. Info on the PHP SAX parser (Expat) can be found here. Alternatively there is a libxml based DOM parser named SimpleXML. A DOM based parser will be easier to work with but it is typically a few orders of magnitude slower.
PHP XML parse - can it be faster?
Consider using an XML database (e.g. eXist or BaseX). At this sort of size, it will be much more efficient.
Very fast parser (php) for huge xml-feeds
With the PHP XML parser you can parse chunk by chunk: http://php.net/manual/en/function.xml-parse.php
So you can load the XML file line by line and push it to your XML parser. Without any surrounding framework, I expect this to be the fastest.
I'm not sure what will happen if you load the XML directly by http://…, if it is possible to read the content before the whole file is loaded.
Which is much faster, XMLParser or SimpleXML
In most cases, XML Parser will be much slower both in terms of development and execution, mainly because you have to write/execute tons of userland PHP code to navigate/read your document.
In some cases, you can find some improvement using XMLReader (not sure about XML Parser) but the cost is extra development time and harder maintenance. Since your application already uses SimpleXML and only uses 250 KB, your time will most likely be better spent on other areas of your application. 500ms seems quite a lot for some XML processing with SimpleXML, you should profile that and/or post your most CPU-intensive routine in another question for optimization.
Best XML Parser for PHP
I would have to say SimpleXML takes the cake because it is firstly an extension, written in C, and is very fast. But second, the parsed document takes the form of a PHP object. So you can "query" like $root->myElement
.
Speed up parsing XML documents with DOMDocument class in PHP and with namespaces
Xpath queries are much faster than doing normal traversal using DOM.
Try below code and let me know if it improves the performance.
<?php
$input_file=scandir($OIB_path);//Scanning directory for files
foreach ($input_file as $input_name){
if($input_name=="." || $input_name=="..")
continue;
$OIB_file=$OIB_path . $input_name;
$doc = new DOMDocument();
$doc->load( $OIB_file );
$xpath = new DOMXPath($doc);
$xpath->registerNameSpace('x', 'http://apis-it.hr/umu/2015/types/kp');
$elements = $xpath->query('//x:PinCountryCodeId/x:PinPrimatelja');
if ($elements->length > 0) {
foreach ($elements as $element) {
echo $element->nodeValue.'<br>';
}
}
}
?>
PHP: is JSON or XML parser faster?
I didn't do any benchmark but...
Since JSON is only a description of nested string sequences, without the need to offer a DOM interface, attributes parsing and other subtle stuff, my guess is that a JSON parser is WAY faster that an XML parser.
Related Topics
What Are .Tpl Files? PHP, Web Design
Http_Build_Query with Same Name Parameters
Apache Mod Rewrite for Laravel
Php: Get N-Th Item of an Associative Array
How to Pass Parameters by Reference Using Call_User_Func_Array()
PHP Composer Behind Http Proxy
Flatten Multidimensional Array Concatenating Keys
Parsing JSON Array with PHP Foreach
Mysql: Add Sequence Column Based on Another Field
PHP How to Import All Classes from Another Namespace
PHP _Php_Incomplete_Class Object with My $_Session Data
Laravel 5.4 Field Doesn't Have a Default Value
Inkscape Inside PHP/Apache Doesn't Render Fonts to Png
Why Doesn't This Code Simply Print Letters a to Z