Git Product home page Git Product logo

Comments (8)

staabm avatar staabm commented on August 19, 2024

how big is "large data"? megabytes? gigabytes?

from xml.

cedtaz avatar cedtaz commented on August 19, 2024
var_dump(strlen($value)); //1211794
$writer->text($value);

Sometimes, I don't have the errors... it depends perhaps servor memory ?

from xml.

staabm avatar staabm commented on August 19, 2024

which php version do you use?

from xml.

cedtaz avatar cedtaz commented on August 19, 2024

PHP 5.6

from xml.

evert avatar evert commented on August 19, 2024

This is very interesting. However, I think this bug should be reported at bugs.php.net, as the text function is just a part of XMLWriter.

You can report it here: http://bugs.php.net/

If you'd like, please leave a comment here with the php bug id, so we can keep an eye on it.
As a workaround, you might want to try splitting up your $value variable and call text() multiple times.

from xml.

GDmac avatar GDmac commented on August 19, 2024

How are you writing @cedtaz ? can you include an example PHP snippet?

@evert looking at the write example

$service = new Sabre\Xml\Service();
echo $service->write('foo','bar');

Inside service->write, you use a hardcoded openMemory() on the XMLwriter,
I would suggest adding another method that uses XMLwriter->openURI() to write to a stream.

The same goes for XMLreader. The parse method forces a string in parse()
https://github.com/fruux/sabre-xml/blob/master/lib/Service.php#L109
I added/tested the following method to read from a file or url,
Instead of XMLreader->xml(string), this uses XMLreader->open(uri)
which will stream and accept very large files too.

    function parseUri($uri, $contextUri = null, &$rootElementName = null, $encoding = null, $options = 0){
        $r = $this->getReader();
        $r->contextUri = $contextUri;
        $r->open($uri, $encoding, $options);

        $result = $r->parse();
        $rootElementName = $result['name'];
        return $result['value'];
    }

(hattip for idea: https://coderwall.com/p/tqggjq/parsing-large-xml-files-using-php )

EDIT: While this may allow to read/write large data sets, memory usage might still be an issue, as the reader continues to read and put the array/structure in memory. An interesting idea might be something like a streamWriter and a streamReader and connect the two with a service to filter from in to out :-)

from xml.

evert avatar evert commented on August 19, 2024

Inside service->write, you use a hardcoded openMemory() on the XMLwriter,
I would suggest adding another method that uses XMLwriter->openURI() to write to a stream.

openURI might help a bit, but it also depends a bit on the situation. Writing to php://memory will make little difference, to php://temp will write to disk, which may be good if that's what you're looking for.

But yea you are not prevented from doing this. Just call getWriter() on the service and initialize the writer yourself. The write() function is there to address the most common use-case.

Same goes a bit for the reader. I'd definitely be interested in a PR to add parseURI and writeURI though!

EDIT: While this may allow to read/write large data sets, memory usage might still be an issue, as the reader continues to read and put the array/structure in memory. An interesting idea might be something like a streamWriter and a streamReader and connect the two with a service to filter from in to out :-)

Also for these use-case you are definitely not restricted from doing this. If, say, you have a massive atom feed, you could use the reader manually, and only let the xml -> object mapper do its thing for every entry element in an atom feed. Regardless for reading you need to decide at one point which element you are ultimately 'streaming'. So for an atom feed this could be per-entry.

But yea I'm interested in suggestions otherwise.

from xml.

evert avatar evert commented on August 19, 2024

I'm closing this ticket because it's been a while since the last comment.

If this is indeed still an issue, feel free to comment here so we can continue discussing.

from xml.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.