Skip to main content
Published: March 14 2012, 6:14:00 PMUpdated: November 28 2020, 10:21:45 PM

The Current LMS php code samples use Curl to post attachments and xml requests to eBay , by loading them into memory prior to the requests(Loading Huge XML data into variables a.k.a memory). Is there a better way of making this sample consume less memory(especially while handling huge Bulk Data Exchange requests)?

The current code sample listed at https://ebaydts.com/eBayKBDetails?KBid=1472 Builds the POST data by loading the "UploadFileRequest" and the "Bulk Data Exchange" requests in to the memory.

if you open \LargeMerchantServicesPHPSamples\application\UploadFile\MultiPartMessage.php

You should find the Buiild functionr eturning the Request below :

<?php
/*  © 2013 eBay Inc., All Rights Reserved */
/* Licensed under CDDL 1.0 -  http://opensource.org/licenses/cddl1.php */

     public static function build($request, $file)
     {
          $requestPart   = '';
         $requestPart  .= "--" . self::$MIME_BOUNDARY . self::$CRLF;
         $requestPart  .= 'Content-Type: application/xop+xml; charset=UTF-8; type="text/xml; charset=UTF-8"' . self::$CRLF;
         $requestPart  .= 'Content-Transfer-Encoding: binary' . self::$CRLF;
         $requestPart  .= 'Content-ID: ' . self::$URN_UUID_REQUEST . self::$CRLF . self::$CRLF;
         $requestPart  .= $request . self::$CRLF;
          
         $binaryPart = '';
         $binaryPart .= "--" . self::$MIME_BOUNDARY . self::$CRLF;
         $binaryPart .= 'Content-Type: application/octet-stream' . self::$CRLF;
         $binaryPart .= 'Content-Transfer-Encoding: binary' . self::$CRLF;
         $binaryPart .= 'Content-ID: <' . self::$URN_UUID_ATTACHMENT . '>' . self::$CRLF . self::$CRLF;
         $binaryPart .= $file . self::$CRLF;
         $binaryPart .= "--" . self::$MIME_BOUNDARY . "--";
         
        return $requestPart . $binaryPart;
     }     

Called as - >   $request = MultiPartMessage::build($requestBody,$file);// where $requestBody and $file are the file contents of the UploadFIleRequest and the BDX Attachment respectively.

However if your attachments are huge and if you would like to post the Request and the attachment files using curl, by specifying the file paths , rather than loading the file contents into the memory, you can do so by making minor changes to the Codesample as below.

 

 

 

 

How well did this answer your question?
Answers others found helpful