title: Setting up cron job to pull HTTP request and create/cache file from results
body: <p>First thanks for any help that you can provide. I am somewhat new to PHP and this is the first "Web Service" I have had to create.</p>
  
  <p>THE GOAL:
  I need to pull XML data from another server. This company's API is setup so that you must give an IP and so you can only pull data from server to server instead of client to server. The data is pulled from the API using HTTP requests...very similar to YQL. (in essence the structured query is located in the URL).  This API also requires that my server only ping's their server every 10-15 mins, in order to cut down on server requests. </p>
  
  <p>The logical thought in my head was to setup: a cron job to run a PHP script every 10 mins. The PHP scripts would then do the following:
  1. Make the HTTP request
  2. Open an existing file or create one (on my server)
  3. Take the returned XML data from the API and write to the newly opened file. 
  4. Convert that XML to JSON. 
  5. Save the JSON
  6. Cache the JSON file
  7. STOP</p>
  
  <p>My thought was to use curl and fopen for the first 3 steps. I found a basic script that will do this on PHP.net (as shown below). After that I am pretty much lost on how to proceed. </p>
  
  <pre><code>&lt;?php
  
  $ch = curl_init("http://www.example.com/");
  $fp = fopen("example_homepage.txt", "w");
  
  curl_setopt($ch, CURLOPT_FILE, $fp);
  curl_setopt($ch, CURLOPT_HEADER, 0);
  
  curl_exec($ch);
  curl_close($ch);
  fclose($fp);
  ?&gt;
  </code></pre>
  
  <p>I would REALLY appreciate any help on this. Also, if you have the time to please comment and explain what you are doing in any code examples and why....that would HELP out a lot. I truly want to learn not just grab a snippet and run. So, your comments are vital for me. </p>
  
  <p>thank!!!</p>