} function process_json($filename, $last_data) { // Return data array or false if not available. global $redis; $timestamp = $redis->get($filename . "-mtime"); if ($timestamp === FALSE) { $timestamp = 0; } $ret = array("file_timestamp" => $timestamp, "content_timestamp" => false, "content" => false); $ret["content"] = json_decode($redis->get($filename), true); if (isset($ret["content"]["timestamp"])) { $ret["content_timestamp"] = $ret["content"]["timestamp"]; } else { $ret["content_timestamp"] = $ret["file_timestamp"]; } if ($ret["content_timestamp"] < $last_data || $ret["file_timestamp"] < $last_data) { return false; } return $ret; } // Populate data $ret["twitter"] = process_json("data:twitter.json", $last_data); $ret["data"] = process_json($filename, $last_data); $ret["status"] = "success"; http_cache_etag(); http_send_content_type("application/json"); http_send_data(json_encode($ret)); // Update statistics $redis->incr("stats:web:json:processed"); stat_update("web:json:processed");
<?php require_once 'initialize.php'; /* Initialize Global array Reason for the use of Array: Processing speed is a lot faster than modifiing CSV data constantly. */ $GLOBALS['z'] = array(); // Product Category Loop for ($i = 0; $i < sizeOf($product_categories); $i++) { // Pass array value into Query Function $response = product_categories_items($product_categories[$i]['queryValue']); process_json($response, $product_categories[$i]); } write_csv(); function product_categories_items($customQuery) { /* Removed connection information - Private */ $curl = curl_init($API_Call); curl_setopt($curl, CURLOPT_FAILONERROR, true); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $cresult = curl_exec($curl); if (curl_error($curl)) {