#!/usr/bin/php true, CURLOPT_FAILONERROR => true, CURLOPT_URL => $sendTo, CURLOPT_POSTFIELDS => array( "data" => $data, ), CURLOPT_SAFE_UPLOAD => true, )); $response = curl_exec($ch); curl_close($ch); print "data=" . $data; print "\r\n----"; print $response; print "----\r\n"; sleep(1); } //Function for sending notifications to pushover, dont worry about it if you dont use it function pushover($title, $msg) { Global $pushover_app,$pushover_user; curl_setopt_array($ch = curl_init(), array( CURLOPT_URL => "https://api.pushover.net/1/messages.json", CURLOPT_POSTFIELDS => array( "token" => $pushover_app, "user" => $pushover_user, "message" => $msg, "title" => $title, ), CURLOPT_SAFE_UPLOAD => true, )); curl_exec($ch); curl_close($ch); return; } //open the csv file now as a read only file so we do not damage the data $file = fopen($csvFile, 'r'); $x = 1; $data = "["; //loops though the file storing each line as the variable $line while(! feof($file)) { try { $line = trim(fgets($file)); $expl = explode(',', $line); if( sizeof($expl) < 2 || strlen($line) == 0 ) { print('bad line (' . strlen($line) . "/" . sizeof($expl) . '): ' . $line . "\n"); continue; } //Assuming a CSV file of example below // unix time, kWh // 1483228840, 50 // 1483228850, 51 // //$expl will now be an array of 2 parts (0 : Unix time, 1: kWh, ) $data .= '['.$expl[0].',1,'.$expl[1].'],'; print( $x++ . " "); if ($x == $chunkSize && sizeof($data) != 0 ) { sendChunk($data); $x = 1; $data = '['; } } catch ( Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; } } fclose($file); print "\nhit EOL, last chunk\n"; //out of the while loop, close the json if( $x != $chunkSize ) { sendChunk($data); } print "DONE"; //pushover("Stuff Extractor","Done"); //Uncomment if you want to use pushover ?>