} array_push($out['data'], $temp); $offset = 0; } else { // Lines that don't match anywhere above are most likely status messages // and don't need to be parsed. $temp['message'] = $line; array_push($out['data'], $temp); } } } fclose($traceFileHandle); if (!$out['inProgress']) { // If the traceroute command is not running anymore, we can update the db // and delete the files $db->updateTracerouteFinished($id); unlink('traceroutes/' . $id . '.pid'); unlink('traceroutes/' . $id . '.txt'); } // Insert all the parsed information into the db foreach ($out['data'] as $key => $value) { $db->insertTraceroute($id, $value); } // Read the data we just inserted and return it to the client $result = $db->getTraceroute($id); $out['data'] = $result; echo json_encode($out); }); /** * Get-request to /api/info/basic gets the basic stats for all the executed * and saved traceroutes so far.