Note that there are some explanatory texts on larger screens.

plurals
  1. POPossible to write large XML file using cURL_setopt & PHP without fwrite?
    primarykey
    data
    text
    <p>I am having an almost identical problem to <a href="https://stackoverflow.com/questions/1521241/make-curl-write-data-as-it-receives-it">this one</a>, posted in '09. It doesn't appear to be successfully solved, and I have been poring over related questions all day &amp; implementing suggestions I have found. </p> <p>I am attempting to pull dynamic (changes daily) data from an XML source (not a file) and insert into a mySQL database. When I attempt to pull the data without fwrite, the data returns without tags/keys in the output. Thus, I cannot properly assign the data to specific database fields.</p> <p>I decided to write the information to a file and go from there, but the file aborts/"completes" at 334kb every single time. Unfortunately, I am a cURL novice and don't have the chops to see exactly what the issue is. Also, I am using vqMod for OpenCart to do this, otherwise I'd be using straight up PHP.</p> <p>What am I missing? </p> <p>Also, is there a way to pull the xml as an array instead of as a string (thereby potentially bypassing the fwrite step)? Or, should I be writing to some other file type?</p> <p>Any suggestions or a redirect to a solved question I've missed are appreciated.</p> <p>This is the relevant code, commented portions are fixes I've attempted: </p> <pre><code>$curl = curl_init(); $fp = fopen('dir/file.xml' , "w" ); //w+ will not download any information from the url - file is created but empty. //AS IS, downloads first 334KB of file then lands on a blank page //and a 500 error when any of these other options are implemented. curl_setopt($curl, CURLOPT_URL, 'http://www.url.com'); curl_setopt($curl, CURLOPT_FILE, $fp); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); // curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // curl_setopt($curl, CURLOPT_TIMEOUT, 300); // curl_setopt($curl, CURLOPT_NOPROGRESS, false); // curl_setopt($curl, CURLOPT_RANGE, '0-1000'); // $data = array(); $data = curl_exec($curl); fwrite($fp, $data); curl_close($curl); fclose($fp); </code></pre> <p><strong>Update</strong>: Attempted to use simplexml_load_string instead of fwrite() to pull one product's information, but am still having limited success. Example of XML I am using:</p> <pre><code> &lt;?xml version="1.0"?&gt; &lt;response&gt; &lt;root&gt; &lt;part&gt; &lt;![CDATA[PARTNUM]]&gt; &lt;/part&gt; &lt;errorcode&gt;0&lt;/errorcode&gt; &lt;errormsg&gt;&lt;/errormsg&gt; &lt;special&gt;N&lt;/special&gt; &lt;description&gt; &lt;![CDATA[]]&gt; &lt;/description&gt; &lt;price&gt;75&lt;/price&gt; &lt;weight&gt;1.02&lt;/weight&gt; &lt;webpurch&gt;Y&lt;/webpurch&gt; &lt;altnum&gt; &lt;![CDATA[ALT-NUM]]&gt; &lt;/altnum&gt; &lt;active&gt;Y&lt;/active&gt; &lt;redo&gt; &lt;![CDATA[]]&gt; &lt;/redo&gt; &lt;codes&gt; &lt;code&gt; &lt;fieldname&gt; &lt;![CDATA[Mfr Part No]]&gt; &lt;/fieldname&gt; &lt;fieldvalue&gt; &lt;![CDATA[PARTNUM]]&gt; &lt;/fieldvalue&gt; &lt;/code&gt; &lt;code&gt; &lt;fieldname&gt; &lt;![CDATA[Special Code 1]]&gt; &lt;/fieldname&gt; &lt;fieldvalue&gt; &lt;![CDATA[XYZ123]]&gt; &lt;/fieldvalue&gt; &lt;/code&gt; &lt;/codes&gt; &lt;customtag&gt;N&lt;/customtag&gt; &lt;onhand&gt;0&lt;/onhand&gt; &lt;notes&gt; &lt;![CDATA[PRODUCT-SPECIFIC NOTE]]&gt; &lt;/notes&gt; &lt;mfr&gt; &lt;mfr_name&gt; &lt;![CDATA[MFR]]&gt; &lt;/mfr_name&gt; &lt;/mfr&gt; &lt;altpartnums&gt; &lt;altnum&gt; &lt;![CDATA[PARTNUM.12]]&gt; &lt;/altnum&gt; &lt;/altpartnums&gt; &lt;gtrue&gt;N&lt;/gtrue&gt; &lt;group&gt; &lt;![CDATA[GROUP NAME]]&gt; &lt;/group&gt; &lt;categories&gt; &lt;cat&gt;294&lt;/cat&gt; &lt;cat&gt;475&lt;/cat&gt; &lt;/categories&gt; &lt;/root&gt; &lt;/response&gt; </code></pre> <p>This is an example of the $data return for multiple products when I <strong>do not</strong> use fwrite(): 0 N 75 1.02 Y Y <code> </code> <code> </code> N 0 N 294 475 0 N 288 12 Y Y <code> </code> Y 18 Y 222 456 3786 </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload