Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4019216
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:04:40+00:00 2026-05-20T10:04:40+00:00

I have a PHP SOAP web service, using CakePHP, which is returning a variable

  • 0

I have a PHP SOAP web service, using CakePHP, which is returning a variable amount of data back to clients. The amount of data returned can be very little, or huge ( > 10MB but < 100MB).

The problem I’m having is that with larger responses (usually greater than 5 MB), the application runs out of memory and things come crashing down. The first thing I’ve tried changing is using raw SQL queries rather than Cake’s data access level. This way, when I retrieve 10,000 records from the database, Cake won’t try to keep it all in memory.

That has worked really well, although it’s a bad convention. The bigger problem however, is once I have the results, it still runs out of memory transmitting the response. I’m not sure if this is happening when the SoapServer compiles the response, or if the client runs out of memory storing the response, or if it runs out of memory just serializing/rendering the data on the screen.

In any case, it seems like if there were some way to stream the SOAP response back to the client, everything would work a lot better. No matter what the issue is, the data could be broken down into manageable chunks. I don’t know how to do this in PHP though, or if it’s even possible.

Please advise.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T10:04:41+00:00Added an answer on May 20, 2026 at 10:04 am

    You should be getting an error message telling you what exhausted the memory. In theory, this should help you determine what is failing. My guess is that SOAPServer is storing the response in memory before sending a response, likely because it is building an XML DOM using PHP’s DomDocument. The downside of DomDocument (or, possibly SimpleXML) is that the entire document must be processed into memory and valid as a DOM document before the data can be serialized into XML.

    A better way to stream large chunks of XML data would be to use PHP’s XMLWriter extension. Unlike DOM, it does not need to store the entire document into memory and it expects you to handle document validation. You can use this extension to output directly to the HTTP response using the XMLWriter::openUri function. This means that you can perform the following operations in order and have minimal memory overhead:

    1. Open a connection to the database
    2. Search for the stuff you need
    3. Create an instance of XMLWriter using the XMLWriter::openUri function with the parameter php://output for the URI. This will push everything to the output (similar to print/echo) and store (almost) nothing in memory. Make sure you’ve already pushed out any headers, cookies, etc you need first, just like any other outputting check.
    4. Create the SOAP preamble.
    5. Loop through the items you are going to return in the soap response, adding the elements to the output.
    6. Create the SOAP postamble

    As a side note, the reverse of XMLWriter is XMLReader, if you are interesed in reading large XML files that cannot be opened using normal methods due to memory limits.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.