We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 39287
    • 13 Posts
    Hi dear all!

    It's been 3 month since I'm using MODx Revo 2, and my project is really near it's launch. I was tweaking all small details and suddenly came accross a problem, which I did not expect (or even think of, actually). The problem is - Low memory error in mod.parser class.

    Here's the description:

    There's an external service that produces files (.pdf), to which I make a soap-call from a snippet. I have to do it from modx environment, sinse I use some user-fields to make a soap-call.

    After I got the file, I need to return it to the user as a downloadable file (usually about 1.5Mb).

    Here's the snippet:

    <?php
    $invoice_no = 'Invoice';
    if (isset($invoiceid)) $invoice_id = $invoiceid; else
    $invoice_id = $_REQUEST['id'];
    
    $client = new SoapClient("someservice/?wsdl", array("trace"=>true)); 
    
    
        try {
        	
        	$fd = $client->GetInvoicePdf(array(id => $invoice_id));
        
    	$invoicepdf = $fd->GetInvoicePdfResult;
        
           
        }
        catch (SoapFault $soapFault) {
            var_dump($soapFault);
            echo "Request :
    ", htmlentities($client->__getLastRequest()), "
    ";
            echo "Response :
    ", htmlentities($client->__getLastResponse()), "
    ";
        }
        
        
        header("Content-Disposition: atachment; filename=invoice_".$invoice_no.".txt");
    	header("Content-Type: application/octet-stream");
    	header("Content-Length: ".strlen($invoicepdf));
    	header("Pragma: no-cache");
    	header("Expires: 0");/**/
    
    	print($invoicepdf);


    Everything goes alright until I try to return the .pdf (by print()) I got as a resource - I immediately get an error in modparser.class.php on line 150:

    $matches[$matchCount][1]= substr($content, ($openPos +strlen($prefix)), $innerTagLength);
    


    Any ideas why it's happening? Maybe there's a 'right' approach to this kind of tasks?

    I'll greatly appreciate your help, thanks!

    PS: there's no problems in the soap-call, it's working alright. The same exact code, on the same server run outside of modx environment works perfectly and returns the requested pdf.
    [ed. note: afterdark last edited this post 14 years, 5 months ago.]
      • 3749
      • 24,544 Posts
      Try this:

      return $invoicepdf;
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 39287
        • 13 Posts
        tried, nothing changed ((
          • 39287
          • 13 Posts
          I guess I'll have to use an external script.. This works OK, but does not look neat (all these friendly URLs - and then a link, showing the real folder structure), so I was hoping there's a common solution to this kind of tasks.
            • 3749
            • 24,544 Posts
            Try saving the pdf file and returning an href tag with a link to it.

              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 39287
              • 13 Posts
              Bob, thanks for your advice, I did it that way already.

              It works alright, although, it makes my users to click twice: first to generate the file and make a link, second — to download.
                • 3749
                • 24,544 Posts
                I always forget how to do this, but I think there's a way to forward them to a static resource with no template, the content/type set to app pdf, and content_dispo set to attachment. That might cut out the extra step.



                ------------------------------------------------------------------------------------------
                PLEASE, PLEASE specify the version of MODX you are using.
                MODX info for everyone: http://bobsguides.com/modx.html
                  Did I help you? Buy me a beer
                  Get my Book: MODX:The Official Guide
                  MODX info for everyone: http://bobsguides.com/modx.html
                  My MODX Extras
                  Bob's Guides is now hosted at A2 MODX Hosting