Note that there are some explanatory texts on larger screens.

plurals
  1. POCan i make a scheduled query to an API using php and save it locally?
    primarykey
    data
    text
    <p>I made a page that retrieves information from an API. It is taking about 10-20 seconds to get the response from their server. The request is done fro js through a PHP proxy to avoid cross-domain issues. I'm wondering, as the data is not like to be changing often (it is congressman's data) I might make a request daily and store it in my server so the page loads faster, I can provide a "refresh" button incase the user needs it. How can that be done? I'm just starting in web development and i see that is necessary knowledge of several different languages and frameworks, now I'm diving into js, but i got this PHP hack working for my requests, bottom line i know almost nothing of PHP yet. </p> <p><strong>[edit]</strong> ok I got the cron working! Now how do i save the document.xml from php script? I tried:</p> <pre><code>$c_t = fopen('file.xml', 'ab+'); fwrite($c_t, date('Y-m-d H:i:s')."\n\n"); //add timestamp to theverbose log fwrite($c_t,$xml); </code></pre> <p>inserted just before `curl_close($session);</p> <p>The file was saved, but only with the timestamp...</p> <p>here's what i got...</p> <pre><code>&lt;?php // PHP Proxy --- only 'GET' // Based on script from yahoo's example @ http://developer.yahoo.com/javascript/samples/proxy/php_proxy_simple.txt // tweaked by vk // hostname - just base domain define ('HOSTNAME', 'http://www.camara.gov.br'); // Get the REST call path from the AJAX application - js; $path = $_GET['yws_path1']; // assign yo url $url = HOSTNAME.$path; //Open the Curl session $session = curl_init($url); // Don't return HTTP headers. Do return the contents of the call curl_setopt($session, CURLOPT_HEADER, false); curl_setopt($session, CURLOPT_HTTPGET, true); //set user agent, that did it!!! copied from browsers... curl_setopt($session, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.76 Safari/537.36'); // The web service returns XML. Set the Content-Type appropriately header("Content-Type: text/xml"); // Make the call $xml = curl_exec($session); // done, shutDown. curl_close($session); ?&gt; </code></pre>
    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.
    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