0) { $taskString = file_get_contents($taskDir.'/'.$taskfiles[0]); $task = json_decode($taskString, true); // if there are any requests to do, do the first if(count($task['requests']) > 0) { doRequest($task['requests'][0]); echo "Request done"; array_shift($task['requests']); $taskString = json_encode($task); $taskfile = fopen($taskDir.'/'.$taskfiles[0], 'w'); if($taskfile){ fwrite($taskfile, $taskString); fclose($taskfile); } } // if there are no Requests left, send the E-Mail else { sendEmail($task['email'], $taskDir.'/'.$taskfiles[0]); echo "Email sent"; unlink($taskDir.'/'.$taskfiles[0]); } } else { echo "Task dir Empty"; } } else { echo "no Task dir"; } ?>